Total Pageviews

Translate

November 10, 2015

RGB-to-HSI and HSI-to-RGB Conversions

by 4hathacker  |  in Image Processing at  8:54 AM

RGB to HSI conversion is one of the methods for image enhancement. Let us first discuss about RGB and HSI models and then using simple formulas just see how this conversion happens.



We have studied about RGB Color model in one of the posts earlier.Let us revise the RGB once again only the part that is important for HSI conversion.
In the RGB model, an image consists of three independent image planes, one in each of the primary colours: red, green and blue. Specifying a particular colour is by specifying the amount of each of the primary components present. Figure shows the geometry of the RGB colour model for specifying colours using a Cartesian coordinate system. The greyscale spectrum, i.e. those colours made from equal amounts of each primary, lies on the line joining the black and white vertices.




In HSI model, color can be specified by three attributes/quantities namely hue, saturation and intensity. 
Hue is a color attribute which is used to describe a pure form of color (may be pure yellow, red or orange).
Saturation is a measure of degree to which a pure color is diluted by white light.
Intensity is the information of colors in the image.
All in one, we can say that HSI model is in close relation with the color perception of human beings.


Conversion formula:
In the image below, see for the rgb_to_hsi conversion formula and also find hsi_to_rgb conversion formula in the next image.



MATLAB Program:
Now let us create a simple program which asks for an image location (use inverted quotes for location) and then gives us back the converted HSI image. Here I am only giving the program code built into a function for rgb_to_hsi conversion. Try yourself to build a code for hsi_to_rgb conversion of image using the formula given.

function rgb_to_hsi()

x = input('Enter the loaction of RGB Color image: ');
rgb = imread(x);figure;
imshow(rgb);title('RGB image');

%Represent the RGB image in [0 1] range
I = double(rgb)/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);

%Normalise 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(rgb));
HSI(:,:,1)=H;
HSI(:,:,2)=S;
HSI(:,:,3)=I;

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


Thats enough for RGB and HSI. To know more about that just search on google for Munsell Color System. It will get you to deeper concepts and similar algorithms.


2 comments:

  1. With the various software program and purposes that we've as we speak when it come to on-line information, it can be crucial as properly to discover a file format that makes our information simple to handle however not simple to change. If you want to learn more about this topic please visit https://onlineconvertfree.com/convert-format/m4a-to-mp3/

    ReplyDelete
  2. i was lost with no hope for my wife was cheating and had always got away with it because i did not know how or always too scared to pin anything on her. with the help a friend IN PERSON OF PAIGE who recommended me to who help hack her phone, email, chat, sms and expose her for a cheater she is. I just want to say a big thank you to HACKINTECHNOLOGY@GMAIL.COM . am sure someone out there is looking for how to solve his relationship problems, you can also contact him for all sorts of hacking job..he is fast and reliable. you could also text +1 669 225 2253

    ReplyDelete

Like Our Facebook Page

Nitin Sharma's DEV Profile
Proudly Designed by 4hathacker.