如何使用 matplotlib 绘制 YCBCR 颜色 space 图像?
How to Plot YCBCR color space image with matplotlib?
这是我的代码,它显示除 YCBCR 之外的所有颜色 spaces,
Notation:ConvertLayer 转换图像的颜色space
fig=plt.figure(figsize=(9, 9))
for images, labels in train_ds.take(1):
for i in range(16):
plt.subplot(5, 5, i + 1)
color_space = COLOR_SPACES[i%5]
image = tf.expand_dims(images[i//5] ,axis=0)
image = augmentation(NormalLayer(color_space)(tf.cast(image,tf.float32)))
if color_space=="YCBCR":
image = tf.cast(image, tf.uint8)
image = ConvertLayer(color_space)(image)
#image = tf.cast(image * 255.0, tf.uint8)
lbl = "{}({})".format(class_names[labels[i//4].numpy().argmax()] , color_space )
plt.imshow(tf.squeeze(image))
plt.title(lbl)
plt.axis("off")
break
我需要在 matplotlib 中可视化它。
通过以下代码,我能够在 matplotlib 中可视化图像。
import matplotlib.pyplot as plt
import numpy as np
x=plt.imread("/content/car.jpeg")
y=rgb2ycbcr(x)
fig = plt.figure(figsize=(10, 7))
rows = 1
columns = 2
fig.add_subplot(rows, columns, 1)
plt.imshow(x)
plt.axis('off')
plt.title("RGB")
fig.add_subplot(rows, columns, 2)
plt.imshow(y)
plt.axis('off')
plt.title("YCBCR")
def rgb2ycbcr(im):
xform = np.array([[.299, .587, .114], [-.1687, -.3313, .5], [.5, -.4187, -.0813]])
ycbcr = im.dot(xform.T)
ycbcr[:,:,[1,2]] += 128
return np.uint8(ycbcr)
输出:
这是我的代码,它显示除 YCBCR 之外的所有颜色 spaces,
Notation:ConvertLayer 转换图像的颜色space
fig=plt.figure(figsize=(9, 9))
for images, labels in train_ds.take(1):
for i in range(16):
plt.subplot(5, 5, i + 1)
color_space = COLOR_SPACES[i%5]
image = tf.expand_dims(images[i//5] ,axis=0)
image = augmentation(NormalLayer(color_space)(tf.cast(image,tf.float32)))
if color_space=="YCBCR":
image = tf.cast(image, tf.uint8)
image = ConvertLayer(color_space)(image)
#image = tf.cast(image * 255.0, tf.uint8)
lbl = "{}({})".format(class_names[labels[i//4].numpy().argmax()] , color_space )
plt.imshow(tf.squeeze(image))
plt.title(lbl)
plt.axis("off")
break
我需要在 matplotlib 中可视化它。
通过以下代码,我能够在 matplotlib 中可视化图像。
import matplotlib.pyplot as plt
import numpy as np
x=plt.imread("/content/car.jpeg")
y=rgb2ycbcr(x)
fig = plt.figure(figsize=(10, 7))
rows = 1
columns = 2
fig.add_subplot(rows, columns, 1)
plt.imshow(x)
plt.axis('off')
plt.title("RGB")
fig.add_subplot(rows, columns, 2)
plt.imshow(y)
plt.axis('off')
plt.title("YCBCR")
def rgb2ycbcr(im):
xform = np.array([[.299, .587, .114], [-.1687, -.3313, .5], [.5, -.4187, -.0813]])
ycbcr = im.dot(xform.T)
ycbcr[:,:,[1,2]] += 128
return np.uint8(ycbcr)
输出: