Skip to content
Related Articles

Related Articles

Display the red, green and blue color planes of a color image in MATLAB
  • Last Updated : 28 Mar, 2019

Prerequisite – RGB image representation
A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for specifying the color of the corresponding pixel. Here we use the RGB color format, so the third order will take 3 values of Red, Green ans Blue respectively. The values of the rows and columns depends on the size of the image.


  • Load the image into a variable J by using imread().
  • Store the number of rows and columns of the image in variables, r and c.
  • Create 3 zero matrices R, G and B (one for each of the 3 colors) of size rXc.
  • Store the corresponding color plane of the image in the corresponding zero matrix.
    1: Red
    2: Green
    3: Blue 
  • Display the images by using imshow(), but typecast them into uint8 first.


% MATLAB code to display the red, green and blue
% color planes of a color image
% read the image
I = imread('lenna.png');
% rows and columns in the image
r = size(I, 1);
c = size(I, 2);
% creating zero matrices
R = zeros(r, c, 3);
G = zeros(r, c, 3);
B = zeros(r, c, 3);
% storing the corresponding color plane
% red plane
R(:, :, 1) = I(:, :, 1);
% green plane
G(:, :, 2) = I(:, :, 2);
% blue plane
B(:, :, 3) = I(:, :, 3);
% displaying the images
figure, imshow(uint8(R));
figure, imshow(uint8(G));
figure, imshow(uint8(B));

Input :

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :