Open In App

Display the red, green and blue color planes of a color image in MATLAB

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.

Approach:



Implementation:




% 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 :




Article Tags :