Convert RGB to HSI
28 views (last 30 days)
Show older comments
I am looking for the values in the first row of S of an HSI color model. Unfortunately, I do not get the desired values. I assume it is my conversion from rgb to hsi. Instead I use rgb2hsv. Does this make any difference?
R = [ 120 20 30;
170 20 70;
120 140 70 ]
G = [ 40 150 20;
20 110 20;
25 20 20 ]
B = [20 60 150;
190 20 250;
20 30 40]
I = zeros(3,3,3);
I(:, :, 1) = R;
I(:, :, 2) = G;
I(:, :, 3) = B;
Ir = rgb2hsv(I);
S = Ir(1,:,2)
% Desired output:
% [0.67 0.74 0.70]
%My output:
% [0.83 0.87 0.87 ]
0 Comments
Accepted Answer
DGM
on 27 Nov 2021
Edited: DGM
on 27 Nov 2021
Yes, it makes a difference. Compare the results for HSI, HSL and HSV:
R = [ 120 20 30;
170 20 70;
120 140 70 ];
G = [ 40 150 20;
20 110 20;
25 20 20 ];
B = [20 60 150;
190 20 250;
20 30 40];
rgb = uint8(cat(3,R,G,B));
hsi = rgb2hsi(rgb);
hsl = rgb2hsl(rgb);
hsv = rgb2hsv(rgb);
% the vector of interest
hsi(1,:,2)
ans =
0.6667 0.7391 0.7000
hsl(1,:,2)
ans =
0.7143 0.7647 0.7647
hsv(1,:,2)
ans =
0.8333 0.8667 0.8667
MATLAB/IPT does not have tools for HSI or HSL conversions. The HSI/HSL conversion tools I used are found here. There are also others on the File Exchange, though be aware that Pascal Getreuer's popular Colorspace Transformations has a bug in the HSI path and will give the incorrect results.
0 Comments
More Answers (0)
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!