Python cv2.COLOR_YCR_CB2BGR Examples

The following are 6 code examples of cv2.COLOR_YCR_CB2BGR(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cv2 , or try the search function .
Example #1
Source File: neural_style.py    From neural-style-tf with GNU General Public License v3.0 7 votes vote down vote up
def convert_to_original_colors(content_img, stylized_img):
  content_img  = postprocess(content_img)
  stylized_img = postprocess(stylized_img)
  if args.color_convert_type == 'yuv':
    cvt_type = cv2.COLOR_BGR2YUV
    inv_cvt_type = cv2.COLOR_YUV2BGR
  elif args.color_convert_type == 'ycrcb':
    cvt_type = cv2.COLOR_BGR2YCR_CB
    inv_cvt_type = cv2.COLOR_YCR_CB2BGR
  elif args.color_convert_type == 'luv':
    cvt_type = cv2.COLOR_BGR2LUV
    inv_cvt_type = cv2.COLOR_LUV2BGR
  elif args.color_convert_type == 'lab':
    cvt_type = cv2.COLOR_BGR2LAB
    inv_cvt_type = cv2.COLOR_LAB2BGR
  content_cvt = cv2.cvtColor(content_img, cvt_type)
  stylized_cvt = cv2.cvtColor(stylized_img, cvt_type)
  c1, _, _ = cv2.split(stylized_cvt)
  _, c2, c3 = cv2.split(content_cvt)
  merged = cv2.merge((c1, c2, c3))
  dst = cv2.cvtColor(merged, inv_cvt_type).astype(np.float32)
  dst = preprocess(dst)
  return dst 
Example #2
Source File: eye2.py    From faceai with MIT License 5 votes vote down vote up
def hist(img):
    ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
    channels = cv2.split(ycrcb)
    cv2.equalizeHist(channels[0], channels[0])  #输入通道、输出通道矩阵
    cv2.merge(channels, ycrcb)  #合并结果通道
    cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)
    return img 
Example #3
Source File: eye.py    From faceai with MIT License 5 votes vote down vote up
def hist(img):
    ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
    channels = cv2.split(ycrcb)
    cv2.equalizeHist(channels[0], channels[0])  #输入通道、输出通道矩阵
    cv2.merge(channels, ycrcb)  #合并结果通道
    cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)
    return img 
Example #4
Source File: color_pencil.py    From pencil-python with MIT License 5 votes vote down vote up
def color_draw(path="img/sjtu.jpg", gammaS=1, gammaI=1):
    im = Image.open(path)

    if im.mode == 'RGB':
        ycbcr = im.convert('YCbCr')
        Iruv = np.ndarray((im.size[1], im.size[0], 3), 'u1', ycbcr.tobytes())
        type = "colour"
    else:
        Iruv = np.array(im)
        type = "black"

    S = get_s(Iruv[:, :, 0], gammaS=gammaS)
    T = get_t(Iruv[:, :, 0], type, gammaI=gammaI)
    Ypencil = S * T

    new_Iruv = Iruv.copy()
    new_Iruv.flags.writeable = True
    new_Iruv[:, :, 0] = Ypencil * 255

    R = cv2.cvtColor(new_Iruv, cv2.COLOR_YCR_CB2BGR)
    img = Image.fromarray(R)
    # img.show()

    name = path.rsplit("/")[-1].split(".")[0]
    suffix = path.rsplit("/")[-1].split(".")[1]

    save_output(Image.fromarray(S * 255), name + "_s", suffix)
    save_output(Image.fromarray(T * 255), name + "_t", suffix)
    save_output(img, name + "_color", suffix) 
Example #5
Source File: imutils.py    From craves.ai with GNU General Public License v3.0 5 votes vote down vote up
def create_mask(self, img, color):
        img = cv2.cvtColor(img, cv2.COLOR_BGR2Lab)

        if color == 'green':
            threshold = [(20, 0, 128), (235, 128, 255)]
        elif color == 'white':
            threshold = [(100, 110, 110), (200, 140, 140)]

        else:
            raise Exception('Color undefined')
        
        mask = cv2.inRange(img, threshold[0], threshold[1])
        # kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7,7))
        # mask =  cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
        # mask =  cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)

        mask = mask > 0

        # img = cv2.cvtColor(img, cv2.COLOR_YCR_CB2BGR)

        # thres_img = np.zeros_like(img, np.uint8)
        # thres_img[mask] = img[mask]

        binary_img = np.zeros((img.shape[0],img.shape[1]), np.uint8)
        binary_img[mask] = 255

        # cv2.imshow('img', binary_img)
        # cv2.waitKey(0)
        # exit(0)

        return mask 
Example #6
Source File: eye.py    From faceai with MIT License 4 votes vote down vote up
def houghCircles(path, counter):
    img = cv2.imread(path, 0)
    # img = cv2.medianBlur(img, 5)

    x = cv2.Sobel(img, -1, 1, 0, ksize=3)
    y = cv2.Sobel(img, -1, 0, 1, ksize=3)
    absx = cv2.convertScaleAbs(x)
    absy = cv2.convertScaleAbs(y)
    img = cv2.addWeighted(absx, 0.5, absy, 0.5, 0)

    # ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
    # channels = cv2.split(ycrcb)
    # cv2.equalizeHist(channels[0], channels[0])  #输入通道、输出通道矩阵
    # cv2.merge(channels, ycrcb)  #合并结果通道
    # cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)

    # img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

    # cv2.imshow("img2", img)
    # cv2.imshow("grayimg", grayimg)

    circles = cv2.HoughCircles(
        img,
        cv2.HOUGH_GRADIENT,
        1,
        50,
        param1=50,
        param2=10,
        minRadius=2,
        maxRadius=0)

    circles = np.uint16(np.around(circles))
    for i in circles[0, :]:
        # draw the outer circle
        # cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 1)
        # draw the center of the circle
        cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 2)
    # cv2.imshow("img" + str(counter), cimg)
    return (i[0] + 3, i[1] + 3)


#彩色直方图均衡化