Convert RGB to HSI

조회 수: 143 (최근 30일)
Jimmy Neutron
Jimmy Neutron 2021년 11월 27일
편집: DGM 2021년 11월 27일
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 ]

채택된 답변

DGM
DGM 2021년 11월 27일
편집: DGM 2021년 11월 27일
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개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by