Open In App

MATLAB | RGB image representation

RGB image can be viewed as three different images(a red scale image, a green scale image and a blue scale image) stacked on top of each other, and when fed into the red, green and blue inputs of a color monitor, it produces a color image on the screen. 

Advantages of RGB color model

  1. In the displays 
  2. In the cameras
  3. In the scanner

Fig 1 RGB Composition image (primary colors)

Fig 2 Pixel of  any RGB image are formed from the corresponding pixel of the three component

Color planes of RGB image: 



Consider an RGB image array ‘I’ then, One has to add the address of the image in MATLAB drive and then copy the address in the respective code, then only one can use the image.

  1. I(:, :, 1) represents the Red color plane of the RGB image 
  2. I(:, :, 2) represents the Green color plane of the RGB image 
  3. I(:, :, 3) represents the Blue color plane of the RGB image 

Code:




%entering the image address
I=imread("rgb-colors-crossing-02-5714560.jpg");
figure;
%subplot to add on more than one result on same output for better comparison
subplot(2,2,1);
imshow(I);
%for labelling the image
xlabel('original image')
grid on;
%represents the Red colour plane of the RGB image
R=I(:,:,1);
subplot(2,2,2);
imshow(R);
xlabel('RED component is extracted')
grid on;
% represents the Green colour plane of the RGB image
G=I(:,:,2);
subplot(2,2,3);
imshow(G);
xlabel('GREEN component is extracted')
grid on;
%represents the Blue colour plane of the RGB image
B=I(:,:,3);
subplot(2,2,4);
imshow(B);
xlabel('BLUE component is extracted')
grid on;

Output:

Fig 3  Extraction of RGB components from a source image

One more method

  1. There present an image viewer section in the apps section of MATLAB interface there we can analyze or inspect all the characteristics of the image.
  2. To reach there Go to Apps section then go to image processing and computer vision section there you will get Image viewer
  3. One can open any image and inspect its characteristics we will do the same thing by checking the RGB components of an image.
  4.  

Output of the inspections

Fig 4 the original image we took for inspection

Fig 5 Displaying the RGB values of the every single pixel in the format of [RGB]  [0-255]

Fig 6 Displaying the information of the image (observe the class of image which is unit 8 which shows that the color shades will range up to 256 shades )




Article Tags :