我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用cv2.COLOR_YCR_CB2BGR。
def img_recover(img): img1=img[0,:,:,:] img1 = npy.swapaxes(img1, 0, 2) img1 = npy.swapaxes(img1, 0, 1) img1=npy.maximum(-1,npy.minimum(1,img1)) img1=img1*128.0+128.0 # img1=img1.astype(npy.uint8) # img1=cv2.cvtColor(img1,cv2.COLOR_YCR_CB2BGR) return img1
def hisEqulColor(img): ycrcb=cv2.cvtColor(img,cv2.COLOR_BGR2YCR_CB) channels=cv2.split(ycrcb) # create a CLAHE object clahe = cv2.createCLAHE() channels[0] = clahe.apply(channels[0]) cv2.merge(channels,ycrcb) cv2.cvtColor(ycrcb,cv2.COLOR_YCR_CB2BGR,img)
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)