필터 지우기
필터 지우기

MATRIX REPRESENTATION OF COLOUR IMAGES

조회 수: 15 (최근 30일)
Anand P
Anand P 2019년 6월 6일
댓글: Walter Roberson 2019년 6월 8일
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
Walter Roberson 2019년 6월 6일
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');
size(canmap)
ans =
256 3
In order to get a pseudocolor image displayed in color, you need to activate its colormap:
colormap(canmap);
This is done on your behalf if you ask to imshow('canoe.tif')
  댓글 수: 2
Anand P
Anand P 2019년 6월 6일
편집: Anand P 2019년 6월 6일
Thanks for the reply. I have another query.
How do i convert a true colour image (3D RGB image ) into a pseudocolour image (2D image)?
Thanks in advance
Walter Roberson
Walter Roberson 2019년 6월 8일
[pimg, cmap] = rgb2ind(rgbimg);
In this form, rgb2ind will choose the colormap entries. You can also create your own colormap and pass it in, such as
cmap = parula(15);
ping = rgb2ind(rgbimg, cmap);

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KSSV
KSSV 2019년 6월 6일
Read bout rgb2gray
  댓글 수: 5
KSSV
KSSV 2019년 6월 6일
Yes...so 3D is converted to 1D using rgb2gray....REad about imagesc also.
Walter Roberson
Walter Roberson 2019년 6월 6일
canoe.tif is pseudcolor. rgb2gray cannot be used with it. If you did want to convert it to gray for some reason, then you would use one of:
[img, cmap] = imread('canoe.tif');
imgray = rgb2gray( ind2rgb(img, cmap) );
or
[img, cmap] = imread('canoe.tif');
imgray = ind2rgb(img, rgb2gray(cmap) );
That is, you can convert it to RGB first and then convert it to gray, or you can convert the colormap to gray and then apply the gray colormap to the image.

댓글을 달려면 로그인하십시오.


Priysha Aggarwal
Priysha Aggarwal 2019년 6월 6일
편집: Priysha Aggarwal 2019년 6월 6일
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!
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 6월 6일
Matrices with integer data class use value ranges between intmin() and intmax() of the class. For example uint16 images the values range from 0 to 65535. 0 to 255 is only for uint8 images.
Matrices with floating point data class use value ranges between 0 and 1 for RGB images. This applies for single and double both.
You missed out on the possibility of pseudocolor images, which is the situation for canoe.tif

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by