idx是什么意思(idx)
大家好,我是小曜,我来为大家解答以上问题。idx是什么意思,idx很多人还不知道,现在让我们一起来看看吧!
1、什么叫归一化?怎么联系到HSI格式的?
2、我理解的归一化是将数据变成某种相对值关系(它是一种无量纲处理手段),例如:将0~255这间的数据double化为0~1(相对值)。
3、从RGB到HSI只是对同一图像用不同的方式表示,这样有利于使用不同的方法进行处理。
4、例如:我想将一幅图像的饱和度提高,那么直接用RGB不太容易,于是转化为HSI后,就非常容易了。
5、下面是转换代码RGB和HSI的互换代码。
6、--------------------------------------------------------------------------
7、function hsi=rgb2hsi(rgb)
8、%RGB2HSI Converts an RGB image to HSI
9、% HSI=RGB2HSI(rgb) converts an RGB image to HSI. The input image is
10、% assumed to be of size M-by-N-by-3, where the third dimension accounts
11、% for three image planes:red, green, and blue, in that order. If all RGB
12、% component images are equal, the HSI conversion is undefined. Ths input
13、% image can be of class double (with values in the rang[0,1]), uint8, or
14、% uint16.
15、% The output image, HSI, is of class double, where:
16、% hsi(:,:,1)= hue image normalized values to the range [0,1] by
17、% dividing all angle values by 2*pi.
18、% hsi(:,:,2)=saturation image, in the range [0,1].
19、% hsi(:,:,3)=intensity image, in the range [0,1].
20、%Extract the individual component images.
21、rgb=im2double(rgb);
22、r=rgb(:,:,1);
23、g=rgb(:,:,2);
24、b=rgb(:,:,3);
25、%Implement the conversion equations.
26、num=0.5*((r-g)+(r-b));
27、den=sqrt((r-g).^2+(r-b).*(g-b));
28、theta=acos(num./(den+eps));
29、H=theta;
30、H(b>g)=2*pi-H(b>g);
31、H=H/(2*pi);
32、num=min(min(r,g),b);
33、den=r+g+b;
34、den(den==0)=eps;
35、S=1-3.*num./den;
36、H(S==0)=0;
37、I=(r+g+b)/3;
38、%Combine all three results into an hsi image.
39、hsi=cat(3,H,S,I);
40、function rgb=hsi2rgb(hsi)
41、%HSI2RGB Converts an HSI image to RGB.
42、% HSI2RGB Converts an HSI image to RGB, where HSI is assumed to be of
43、% class double with:
44、% hsi(:,:,1)= hue image normalized values to the range [0,1] by
45、% dividing all angle values by 2*pi.
46、% hsi(:,:,2)=saturation image, in the range [0,1].
47、% hsi(:,:,3)=intensity image, in the range [0,1].
48、% The components of the output image are:
49、% rgb(:,:,1)=red;
50、% rgb(:,:,2)=green.
51、% rgb(:,:,3)=blue.
52、%Extract the individaul HSI component images.
53、H=hsi(:,:,1)*2*pi;
54、S=hsi(:,:,2);
55、I=hsi(:,:,3);
56、%Implement the conversion equations.
57、R=zeros(size(hsi,1),size(hsi,2));
58、G=zeros(size(hsi,1),size(hsi,2));
59、B=zeros(size(hsi,1),size(hsi,2));
60、% RG sector (0<=H<2*pi/3).
61、idx=find((0<=H)&(H<2*pi/3));
62、B(idx)=I(idx).*(1-S(idx));
63、R(idx)=I(idx).*(1+S(idx).*cos(H(idx))./cos(pi/3-H(idx)));
64、G(idx)=3*I(idx)-(R(idx)+B(idx));
65、%BG sector (2*pi/3<=H<4*pi/3).
66、idx=find((2*pi/3<=H)&(H<4*pi/3));
67、R(idx)=I(idx).*(1-S(idx));
68、G(idx)=I(idx).*(1+S(idx).*cos(H(idx)-2*pi/3)./cos(pi-H(idx)));
69、B(idx)=3*I(idx)-(R(idx)+G(idx));
70、%BR sector.
71、idx=find((4*pi/3<=H)&(H<=2*pi));
72、G(idx)=I(idx).*(1-S(idx));
73、B(idx)=I(idx).*(1+S(idx).*cos(H(idx)-4*pi/3)./cos(5*pi/3-H(idx)));
74、R(idx)=3*I(idx)-(G(idx)+B(idx));
75、%Combine all three results into an RGB image. Clip to [0,1] to compensate for floating-point arithmetic rounding effects.
76、rgb=cat(3,R,G,B);
77、rgb=max(min(rgb,1),0);
本文到此讲解完毕了,希望对大家有帮助。