Function HSI = rgb2hsi (X)
F = X;
F = im2double (f );
R = f (:,:, 1 );
G = f (:,:, 2 );
B = f (:,:, 3 );
Th = ACOs (0.5 * (r-g) + (r-B ))). /(SQRT (r-g ). ^ 2 + (r-B ). * (G-B) + EPS ));
H = th;
H (B> G) = 2 * pi-H (B> G );
H = H/(2 * PI );
S = 1-3. * (min (R, G), B)./(R + G + B + EPS );
I = (R + G + B)/3;
HSI = CAT (3, H, S, I );
He = H * 2 * PI;
He = histeq (HE );
He = He/(2 * PI );
Se = histeq (s );
Ie = histeq (I );
Choice = input ('1: RGB to HSI/N2: Show HSI image/N3: HSI to RGB image/N4: Tone balanced/N5: Saturation balanced/N6: brightness balancing/N7: HSI balancing/N input your choice :');
Switch choice
Case 1
Figure, imshow (F), title ('rgb image ');
Figure, imshow (HSI), title ('hsi image ');
Case 2
Figure, imshow (F), title ('rgb image ');
Figure, imshow (H), title ('hue image ');
Figure, imshow (s), title ('saturation image ');
Figure, imshow (I), title ('brightness image ');
Case 3
C = hsitorgb (HSI );
Figure, imshow (HSI), title ('hsi image ');
Figure, imshow (C), title ('rgb image ');
Case 4
Rv = CAT (3, he, s, I );
C = hsitorgb (RV );
Figure, imshow (HSI), title ('hsi image ');
Figure, imshow (F), title ('rgb image ');
Figure, imshow (C), title ('rgb image-Hue equalized ');
Case 5
Rv = CAT (3, H, Se, I );
C = hsitorgb (RV );
Figure, imshow (HSI), title ('hsi image ');
Figure, imshow (F), title ('rgb image ');
Figure, imshow (C), title ('rgb saturation balance ');
Case 6
Rv = CAT (3, H, S, ie );
C = hsitorgb (RV );
Figure, imshow (HSI), title ('hsi image ');
Figure, imshow (F), title ('rgb image ');
Figure, imshow (C), title ('rgb brightness balance ');
Case 7
Rv = CAT (3, he, Se, ie );
C = hsitorgb (RV );
Figure, imshow (HSI), title ('hsi image ');
Figure, imshow (F), title ('rgb image ');
Figure, imshow (C), title ('rgb HSI balancer ');
Otherwise
Display ('select error ');
End
End
% Function to convert an HSI image to an RGB image
Function C = hsitorgb (HSI)
HV = HSI (:,:, 1) * 2 * PI;
SV = HSI (:,:, 2 );
IV = HSI (:,:, 3 );
R = zeros (SIZE (HV ));
G = zeros (SIZE (HV ));
B = zeros (SIZE (HV ));
% RG sector
Id = find (0 <= HV) & (HV <2 * PI/3 ));
B (ID) = IV (ID). * (1-sv (ID ));
R (ID) = IV (ID). * (1 + SV (ID). * Cos (HV (ID)./cos (PI/3-hv (ID )));
G (ID) = 3 * IV (ID)-(R (ID) + B (ID ));
% BG sector
Id = find (2 * PI/3 <= HV) & (HV <4 * PI/3 ));
R (ID) = IV (ID). * (1-sv (ID ));
G (ID) = IV (ID ). * (1 + SV (ID ). * Cos (HV (ID)-2 * PI/3 ). /cos (Pi-HV (ID )));
B (ID) = 3 * IV (ID)-(R (ID) + g (ID ));
% BR sector
Id = find (4 * PI/3 <= HV) & (HV <2 * PI ));
G (ID) = IV (ID). * (1-sv (ID ));
B (ID) = IV (ID ). * (1 + SV (ID ). * Cos (HV (ID)-4 * PI/3 ). /cos (5 * PI/3-hv (ID )));
R (ID) = 3 * IV (ID)-(G (ID) + B (ID ));
C = CAT (3, R, G, B );
C = max (min (C, 1), 0 );
End