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.
- RGB color model is the model in which Red, Blue, and Green colors are blended together to form an array of colors
- In this article, we will learn the concept of extraction of RGB components from an image and the calculation of RGB values pixels on the MATLAB interface.
- An RGB image is sometimes referred to as a true color image as the precision with which a real-life image can be replicated has led to the nickname “true color image.”
Advantages of RGB color model
- No transformations are required to display data on the screen.
- It is considered the base color space for various applications
- It is a computationally practical system.
- With the help of additive property, it is used in video displays
- This model is very easy to implement
- Some of its uses are as follows:
- In the displays
- In the cameras
- In the scanner

Fig 1 RGB Composition image (primary colors)
- In MATLAB, an RGB image is basically a M*N*3 array of color pixel, where each color pixel is associated with three values which correspond to red, blue and green color component of RGB image at a specified spatial location.
- the color of any pixel is determined by the combination of the red, green, and blue intensities stored in each color plane at the pixel’s location. Here each color plane is a M*N array.
- Let an RGB image is of class ‘uint8’, i.e. the range of values a color component plane can have is (2 raise to the power 8) which results to [0 – 255 ] ( a total of 256 shades of that color).
So, each individual color plane of An RGB image is capable of showing 256 shade of that color.
So total number of combination of color that can be represented in an RGB image is 256 X 256 X 256 = 16777216, approximately 16 million.

Fig 2 Pixel of any RGB image are formed from the corresponding pixel of the three component
- As can be seen in the above image, Pixel(A) has value (255, 0, 255) and is determined by the combination of intensities stored in the red color plane, green color plane and blue color plane respectively.
- Similarly, pixel(B) has value (127, 255, 0) and is determined in the same manner as pixel(A).
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.
- I(:, :, 1) represents the Red color plane of the RGB image
- I(:, :, 2) represents the Green color plane of the RGB image
- I(:, :, 3) represents the Blue color plane of the RGB image
Code:
Matlab
I=imread( "rgb-colors-crossing-02-5714560.jpg" );
figure;
subplot(2,2,1);
imshow(I);
xlabel( 'original image' )
grid on;
R=I(:,:,1);
subplot(2,2,2);
imshow(R);
xlabel( 'RED component is extracted' )
grid on;
G=I(:,:,2);
subplot(2,2,3);
imshow(G);
xlabel( 'GREEN component is extracted' )
grid on;
B=I(:,:,3);
subplot(2,2,4);
imshow(B);
xlabel( 'BLUE component is extracted' )
grid on;
|
Output:
.png)
Fig 3 Extraction of RGB components from a source image
One more method
- 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.
- To reach there Go to Apps section then go to image processing and computer vision section there you will get Image viewer
- One can open any image and inspect its characteristics we will do the same thing by checking the RGB components of an image.
-
Output of the inspections
.png)
Fig 4 the original image we took for inspection
.png)
Fig 5 Displaying the RGB values of the every single pixel in the format of [RGB] [0-255]
.png)
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 )