def test_yuv(self): rgb = np.array([[[1.0, 1.0, 1.0]]]) assert_array_almost_equal(rgb2yuv(rgb), np.array([[[1, 0, 0]]])) assert_array_almost_equal(rgb2yiq(rgb), np.array([[[1, 0, 0]]])) assert_array_almost_equal(rgb2ypbpr(rgb), np.array([[[1, 0, 0]]])) assert_array_almost_equal(rgb2ycbcr(rgb), np.array([[[235, 128, 128]]])) rgb = np.array([[[0.0, 1.0, 0.0]]]) assert_array_almost_equal(rgb2yuv(rgb), np.array([[[0.587, -0.28886916, -0.51496512]]])) assert_array_almost_equal(rgb2yiq(rgb), np.array([[[0.587, -0.27455667, -0.52273617]]])) assert_array_almost_equal(rgb2ypbpr(rgb), np.array([[[0.587, -0.331264, -0.418688]]])) assert_array_almost_equal(rgb2ycbcr(rgb), np.array([[[144.553, 53.797, 34.214]]]))
def test_yuv(self): rgb = np.array([[[1.0, 1.0, 1.0]]]) assert_array_almost_equal(rgb2yuv(rgb), np.array([[[1, 0, 0]]])) assert_array_almost_equal(rgb2yiq(rgb), np.array([[[1, 0, 0]]])) assert_array_almost_equal(rgb2ypbpr(rgb), np.array([[[1, 0, 0]]])) assert_array_almost_equal(rgb2ycbcr(rgb), np.array([[[235, 128, 128]]])) assert_array_almost_equal(rgb2ydbdr(rgb), np.array([[[1, 0, 0]]])) rgb = np.array([[[0.0, 1.0, 0.0]]]) assert_array_almost_equal(rgb2yuv(rgb), np.array([[[0.587, -0.28886916, -0.51496512]]])) assert_array_almost_equal(rgb2yiq(rgb), np.array([[[0.587, -0.27455667, -0.52273617]]])) assert_array_almost_equal(rgb2ypbpr(rgb), np.array([[[0.587, -0.331264, -0.418688]]])) assert_array_almost_equal(rgb2ycbcr(rgb), np.array([[[144.553, 53.797, 34.214]]])) assert_array_almost_equal(rgb2ydbdr(rgb), np.array([[[0.587, -0.883, 1.116]]]))
def test_yuv_roundtrip(self): img_rgb = img_as_float(self.img_rgb)[::16, ::16] assert_array_almost_equal(yuv2rgb(rgb2yuv(img_rgb)), img_rgb) assert_array_almost_equal(yiq2rgb(rgb2yiq(img_rgb)), img_rgb) assert_array_almost_equal(ypbpr2rgb(rgb2ypbpr(img_rgb)), img_rgb) assert_array_almost_equal(ycbcr2rgb(rgb2ycbcr(img_rgb)), img_rgb) assert_array_almost_equal(ydbdr2rgb(rgb2ydbdr(img_rgb)), img_rgb)
def representative_dataset_gen(): for index, calculate_lr_img in enumerate(calculate_lr_imgs): print(index, "calculate_lr_img.shape=", calculate_lr_img.shape) ypbpr = sc.rgb2ypbpr(calculate_lr_img / 255.0) # RGB to YPbPr x_scale = resize(calculate_lr_img, [320, 480]) # Resize (Height, Width) y = ypbpr[..., 0].astype(np.float32) y = np.expand_dims(y, axis=-1) # Add a dimension to the end y = y[np.newaxis, :, :, :] pbpr = sc.rgb2ypbpr(x_scale / 255)[..., 1:].astype( np.float32) # Extract backward from INDEX = 1 of last dimension pbpr = pbpr[np.newaxis, :, :, :] #print("y.shape=", y.shape) #print("pbpr.shape=", pbpr.shape) #yield [pbpr, y] yield [y, pbpr]
def test_yuv_roundtrip(self, channel_axis): img_rgb = img_as_float(self.img_rgb)[::16, ::16] img_rgb = np.moveaxis(img_rgb, source=-1, destination=channel_axis) assert_array_almost_equal( yuv2rgb(rgb2yuv(img_rgb, channel_axis=channel_axis), channel_axis=channel_axis), img_rgb) assert_array_almost_equal( yiq2rgb(rgb2yiq(img_rgb, channel_axis=channel_axis), channel_axis=channel_axis), img_rgb) assert_array_almost_equal( ypbpr2rgb(rgb2ypbpr(img_rgb, channel_axis=channel_axis), channel_axis=channel_axis), img_rgb) assert_array_almost_equal( ycbcr2rgb(rgb2ycbcr(img_rgb, channel_axis=channel_axis), channel_axis=channel_axis), img_rgb) assert_array_almost_equal( ydbdr2rgb(rgb2ydbdr(img_rgb, channel_axis=channel_axis), channel_axis=channel_axis), img_rgb)
def __call__(self, img): img = np.asarray(img, np.uint8) img = color.rgb2ypbpr(img) return img