[英]RGB to V (from HSV)
我正在尝试将 RGB 图像转换为其值组件。 我不能使用 RGB2HSV function 因为我被指示在没有它的情况下转换它。 如果我没记错的话,图像的值是像素中 R,G 和 B 分量的最大值; 所以这就是我试图实现的。
'''
rgb_copy = self.rgb.copy()
width, height, other = rgb_copy.shape
for i in range(0, width-1):
for j in range(0, height-1):
# normalize the rgb values
[r, g, b] = self.rgb[i, j]
r_norm = r/255.0
g_norm = g/255.0
b_norm = b/255.0
# find the maximum of the three values
max_value = max(r_norm, g_norm, b_norm)
rgb_copy[i, j] = (max_value, max_value, max_value)
cv2.imshow('Value', rgb_copy)
cv2.waitKey()
'''
不幸的是,这似乎不起作用。 当我使用内置的 function 转换它时,它只返回一个与 Value 组件不同的黑色图像。
谁能帮忙或看看我哪里出错了?
详细说明我上面的评论:
因为您尝试通过除以255来标准化 RGB 值,所以我假设您的 RGB 图像是 3 通道unsigned char
图像(每个通道都是0..255之间的unsigned char
值)。
当你克隆它时:
rgb_copy = self.rgb.copy()
您制作rgb_copy
相同类型的图像(即 3 通道unsigned char
)。 然后,您尝试使用每个通道的标准化0..1 float
值填充它。
相反,您可以简单地将每个像素的 RGB 通道的最大值。
就像是:
rgb_copy = self.rgb.copy()
width, height, other = rgb_copy.shape
for i in range(0, width - 1):
for j in range(0, height - 1):
# find the maximum of the three values
max_value = max(self.rgb[i, j])
rgb_copy[i, j] = (max_value, max_value, max_value)
cv2.imshow('Value', rgb_copy)
cv2.waitKey()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.