Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Converting RGB Image to HSI






Converting RGB Image to HSI

H stands for Hue, S for Saturation and I for Intensity.



MATLAB CODE:
Read a RGB Image
A=imread('peppers.png');
figure,imshow(A);title('RGB Image');




%Represent the RGB image in [0 1] range
I=double(A)/255;

R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3);

%Hue
numi=1/2*((R-G)+(R-B));
denom=((R-G).^2+((R-B).*(G-B))).^0.5;

%To avoid divide by zero exception add a small number in the denominator
H=acosd(numi./(denom+0.000001));

%If B>G then H= 360-Theta
H(B>G)=360-H(B>G);

%Normalize to the range [0 1]
H=H/360;

%Saturation
S=1- (3./(sum(I,3)+0.000001)).*min(I,[],3);


%Intensity
I=sum(I,3)./3;


%HSI
HSI=zeros(size(A));
HSI(:,:,1)=H;
HSI(:,:,2)=S;
HSI(:,:,3)=I;



figure,imshow(HSI);title('HSI Image');



















Explanation:

1.    Read a RGB image using ‘imread’ function.
2.    Each RGB component will be in the range of [0 255].  Represent the image in [0 1] range by dividing the image by 255.
3.    Find the theta value. If B<=G then H= theta. If B>G then H= 360-theta
4.    Use ‘acosd’ function to find inverse cosine and obtain the result in degrees.
5.    Divide the hue component by 360 to represent in the range [0 1]
6.    Similarly, find the saturation and the intensity components.
7.    Display the image.










like button Like "IMAGE PROCESSING" page

7 comments:

Naseeb Gill said... Reply to comment

Thanks It is very useful and informative.

Nazia Shaheen said... Reply to comment

This code is not working

Nazia Shaheen said... Reply to comment

This code is not working.

Malvika Oberoi said... Reply to comment

It's working. Thanks alot

Unknown said... Reply to comment

%Saturation
S=1- (3./(sum(I,3)+0.000001)).*min(I,[],3);

for this part I get this error.

"Subscript indices must either be real positive integers or logicals."

Bijal Desai said... Reply to comment

Hey will you please provide me code for RGB to HSL conversion ??? please any body help me for this topic

Unknown said... Reply to comment

can you give me code in matlab to extract plate car's from image

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com