I have an 1D array of three variable i.e. 0,1,2. I want to convert this array into a image of three different color say red for 0, blue for 1 and green for 2. How can i do this?

 채택된 답변

Stephen23
Stephen23 2016년 8월 29일
편집: Stephen23 2016년 8월 29일

0 개 추천

What you have is called an indexed image, which you can read about here:
The MATLAB function ind2rgb converts from an indexed image to an RGB image. It is very simple to use:
>> X = uint8([0,1,2;2,1,1;1,0,0;2,2,0]) % your matrix
X =
0 1 2
2 1 1
1 0 0
2 2 0
>> map = [1,0,0;0,1,0;0,0,1] % [red;green;blue]
map =
1 0 0
0 1 0
0 0 1
>> rgb = ind2rgb(X,map);
and you can view it easily too (compare the image with matrix X):
>> imshow(rgb)
Note that integer and floating point images are handled differently: read the ind2rgb documentation for more information.

추가 답변 (1개)

KSSV
KSSV 2016년 8월 29일

0 개 추천

N = 100 ;
H(:,:,1) = zeros(N,N) ;
H(:,:,2) = ones(N,N) ;
H(:,:,3) = 2*ones(N,N);
image(H)

카테고리

도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기

질문:

2016년 8월 28일

편집:

2016년 8월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by