MATRIX REPRESENTATION OF COLOUR IMAGES
37 views (last 30 days)
Why are some colour imges represented by 2 dimensional matrix while other colour images are represented by 3 dimensional matrix ?
For example, the file autumn.tif (which comes along with MATLAB tool box) is represented by a 3 dimensional matrix while the file 'canoe.tif' is represented by a 2 dimensional matrix ?
How do I convert a colour image represented by a 3 dimensional matrix into a colour image represented by a 2 dimensional matrix
Walter Roberson on 6 Jun 2019
You are seeing the difference between RGB ("Truecolor") images, which are rows x columns x 3, compared to a Pseudocolor images, which are rows x columns plus a something-by-3 colormap:
[canimg, canmap] = imread('canoe.tif');
In order to get a pseudocolor image displayed in color, you need to activate its colormap:
This is done on your behalf if you ask to imshow('canoe.tif')
More Answers (2)
Priysha Aggarwal on 6 Jun 2019
Edited: Priysha Aggarwal on 6 Jun 2019
Images can be represented as both 2D and 3D matrices. When the image is grayscale (i.e. black and white) then we need only 2 channels to represent it. Each entry in the 2D matrix can take values from 0-255 representing grayscale values. Example : Following is a 4x4 grayscale image.
a = [0 10 200 255
50 95 65 210
65 84 152 56
87 196 56 184]
But coloured images need 3 channels representation - RGB. Hence we need a 3D matrix to represent it. Example : m*n*3 matrix represents a coloured image of size m*n (and 3 channels).
To convert 3D to 2D image:
You can either work with any one of the 3 channels as follows:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Or you can convert it to grayscale image using rgb2gray function.
Hope this helps!