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.
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);Answer1:
When you call <a href="http://www.mathworks.com/help/matlab/ref/rgb2hsv.html" rel="nofollow">
rgb2hsv</a> with a
N-by-3 matrix, it is interpreted <em>as a colormap</em>, 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
The colormap syntax explained by the help page for
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.
When you run
D = rgb2hsv(D); it is running it with the above syntax, rather than treating the input as an image.
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.
I simply multiplied by 255 on the resulting matrix from running rgb2hsv on an image. I verified that the hue, saturation, and value were then the correct value and it was. This solved my problem. Be sure to verify. Another weird thing was that those values are a percentage, so 1 means 100% and 0.5 means 50%. This also threw me off.