GeeksforGeeks App
Open App
Browser
Continue

# 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.

• 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:
1. In the displays
2. In the cameras
3. 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.

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

## Matlab

 `%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 )

My Personal Notes arrow_drop_up