如何解决使用 numpy、scipy、skimage 等在 Python 中分别显示图像的每个 ycbcr 通道的最佳方法是什么?
更新:这个函数应该接收一个ndarray
(例如,从pyplot.imread()
获得的)并分别显示每个YCbCr通道:
import numpy as np
import matplotlib.pyplot as plt
from skimage import color
def plot_ycbcr(a):
b = color.rgb2ycbcr(a) # we assume the input image is in RGB--if not,this will
# not give the correct output
b = b.astype(int)
plt.figure()
for i in range(3):
plt.subplot(1,3,i+1)
temp = np.zeros(b.shape,dtype=b.dtype)
temp[:,:,i] = b[:,i]
plt.imshow(color.ycbcr2rgb(temp))
这看起来应该工作,但是由于某种原因,当我尝试转换回 rgb 时,我得到非常小的 (e-10) 浮点数,包括正数和负数。据我所知,RGB 图像甚至不应该具有负值......这里发生了什么,我该如何解决?
旧帖子:
def plot_ycbcr(a):
b = color.rgb2ycbcr(a) # we assume the input image is in RGB--if not,this will
# not give the correct output
plt.figure()
for i in range(3):
plt.subplot(1,i]
plt.imshow(temp)
这是基于绘制图像的每个 RGB 通道的类似函数。有了它,这很容易,因为据我所知,imshow()
将默认使用 RGB 编码显示形状为 (x,y,3)
的任何数组中的图像。
我想我可以传入一些 kwarg 来更改图像编码模式,但我找不到这样的东西。我知道我可以通过单独转换频道或其他方式来找出解决方法,但这听起来很麻烦。那么在 YCbCr 中获得这些的最简单方法是什么?是否可以仅使用我导入的库(可能还有 scipy)来完成?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。