Reputation: 611
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);
Upvotes: 1
Views: 6037
Reputation: 65
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.
Upvotes: 0
Reputation: 30579
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.
The colormap syntax explained by the help page for rgb2hsv
:
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.
Upvotes: 1