如何使用matplotlib绘制YCBCR颜色空间图像?

发布于 2025-01-29 11:16:28 字数 799 浏览 2 评论 0原文

这是我的代码,它显示了除ycbcr之外的所有

空间

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

颜色 =“ https://i.sstatic.net/it7rx.png” alt =“在此处输入图像说明”>

我只需要在matplotlib中可视化它。

This is my code it shows all color spaces except YCBCR ,,

Notation:ConvertLayer converts color space of image

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

enter image description here

I need to visualize it just in matplotlib.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小伙你站住 2025-02-05 11:16:28

使用以下代码,我能够在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)

输出:

With the following code I was able to visualize the image in 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)

Output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文