RGB和HSV空间之间的转换 [英] conversion between RGB and HSV space
问题描述
我目前正在尝试使用 rgb2hsv
函数将两个对象从RGB空间转换为HSV空间,一个是图像,另一个是RGB值矩阵,但是我对矩阵值部分的结果不一致。
I am currently trying to convert two objects from RGB space to HSV space using the rgb2hsv
function, one being an image, the other being a matrix of RGB values, but my results for the value part of the matrix are not consistent.
矩阵 I
中的值的结果在1到255之间,但在第二个矩阵<$ c $中c> D ,它们介于0和1之间。有人知道为什么会这样吗?
The results for value in matrix I
are between 1 and 255, but in the second matrix D
, they are between 0 and 1. Does anybody know why this is the case?
I = imread('00000001.jpg');
I = rgb2hsv(I);
D = [221 12 26; 30 68 76; 40 47 27; 165 87 25; 37 59 26; 148 125 91];
D = rgb2hsv(D);
推荐答案
当你打电话给 rgb2hsv
, N -by-3
矩阵,将解释为色彩图,而不是图像甚至图像强度。色彩图的值为[0,1],而 uint8
图像的值为[0,255]。这就是 rgb2hsv
所期望的。
When you call rgb2hsv
with a N-by-3
matrix, it is interpreted as a colormap, not an image or even image intensities. A colormap has values on [0,1], while a uint8
image has values on [0,255]. This is what rgb2hsv
expects.
rgb2hsv帮助页面解释的colormap语法
:
H = rgb2hsv(M)
转换RGB颜色映射到HSV颜色映射。
每个地图都是一个矩阵,包含任意数量的行,正好是三列,
和0到1之间的元素。
H = rgb2hsv(M)
converts an RGB color map to an HSV color map. Each map is a matrix with any number of rows, exactly three columns, and elements in the interval 0 to 1.
运行 D = rgb2hsv(D);
时,它使用上述语法运行它,而不是将输入视为图像。
When you run D = rgb2hsv(D);
it is running it with the above syntax, rather than treating the input as an image.
也就是说,您可以将输出的第三列 D
除以255,因为生成的奇异色图似乎只是缩放了价值元素。
That said, you can just divide the third column of the output D
by 255 since the resulting bizarro colormap seems to simply have scaled value elements.
这篇关于RGB和HSV空间之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!