Total Pageviews

Translate

September 16, 2015

RGB Color model and Images

by 4hathacker  |  in Image Processing at  7:24 PM

In the previous post we have learnt about the very basic commands of image processing i.e., how to read and write the image, how to find out some information about the image like as size, pixels, etc.

In this second lesson, we are going to learn some basic conventions for RGB color model using an example.



In RGB color model, the image consists of  3 planes overlapped to each other. These planes are R, G and B. This is also called true color format. R stands for Red, G for Green and B for Blue. These are the primary colors that the receptive cells of our eyes called the 'cons' can detect. There are some other receptive cells present in our eyes which are responsible for the intensity variation of the color, these are called 'rods'. Now, RGB model of color is therefore to be used in different sensors and electronic equipments for representation of digital images and videos.

To show this, whether I am telling the truth or not, lets play with some RGB color image and scale it to see different components of an image.

function image_scale()
q = input('enter the location of image: ');
a = imread(q);
while(1)
     disp('To show original image press 1');
     disp('To show image scaled in red press 2');
     disp('To show image scaled in green press 3');
     disp('To show image scaled in blue press 4');
     disp('To exit press 5');
             b = input('enter your choice: ');
                 
              switch b
                       case 1
                            imtool(a);
                       case 2
                            figure;
                            imagesc(a(:,:,1));
                            title('Red');
                       case 3
                            figure;
                            imagesc(a(:,:,2));
                            title('Green');
                       case 4
                            figure;
                            imagesc(a(:,:,3));
                            title('Blue');
                       case 5
                            b=5;
                            fprintf('u r out of the program !!!');
                            exit
                  otherwise
                            b = input('plz enter the correct choice: ')
               end
end


Here a function image _scale () is defined. This function is pretty easier to understand if you are aware of the 'switch case' technology of the programming. I like this technology very well because it makes our work very simple. Just code under a case, opt for the same case and your work is done.

An image is entered with 'imread()' as expalined in the lesson - 1. And then some information is displayed using 'disp()' in which the string in quotes is to be passed. Here 'b' is a variable in which the choice is to be stored using 'input()' function. This value of variable 'b' then decides where to go and what to do with the image.

In case 1, the image is displayed using 'imtool' function. In the later three cases, image scaling is done using 'imagesc()' function. 'imagesc()' scales image data to the full range of the current colormap and displays the image. Firstly taking R-plane and all x, y values scaling is done. Similary, for 2nd i.e Green and further for Blue. The 3 components of RGB image index into a colormap, in which the value stored is an integer that refers to a row in a matrix called a colormap. Thus, colormap stores the red, green, and blue components in three separate columns. Finally there comes the case 5, which brings you out of the program.

Let us now observe the images so obtained.
(Image from imtool isn't shown here, please inspect in your own pc.)

>> image_scale
enter the location of image: 'peppers.png'
To show original image press 1
To show image scaled in red press 2
To show image scaled in green press 3
To show image scaled in blue press 4
To exit press 5
enter your choice: 1
(similarly you can go through other options)



Please do observe the differences between 'imtool()' and 'imshow()'. Also you can find on your own in the MATLAB Help that we can combine all the three to make the original image as well. Try it and I will tell it later.



0 comments:

Like Our Facebook Page

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