How do I go about generating a colormap from a matlab file containing RGB values

조회 수: 5 (최근 30일)
Hi all !
I'm really stuck on a problem I would appreciate help with :
I have a matlab file containing 359 variables where each variable consists of a 360 x 3 matrix of double RGB values . For example , variable 1 looks like this :
1 1 1
1 1 1
1 1 1
1 1 1
1 0.73 1
1 0.76 1
.
.
.
.
.
and so on until row 360 .
My question is how can I go about loading these values into a matrix from which I can generate a colormap?
I have loaded values from a structure into a matrix and represented it as a colormap pretty easily before but my issue here is that I have three RGB values for each row and I don't know how to 'combine' them to get a number which represents a color (if it is even necessary for me to do that).
Many thanks in advance !
Saba

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 13일
cmap = unique(YourArray, 'rows');
or, better,
cmap = uniquetol(YourArray, 1, 'ByRows', true, 'DataScale', 0.004);
cmap is now your colormap.
  댓글 수: 3
Saba Malik
Saba Malik 2016년 5월 14일
can i just ask why you specified data scale as 0.004 ? ?
Walter Roberson
Walter Roberson 2016년 5월 16일
0.004 is slightly less than 1/255. I was aiming to have a change of less than 1/255 be recognized as being the same color.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 5월 13일
Use the colormap() function after you've displayed your grayscale or indexed image
imshow(grayImage);
colormap(variable1); % variable1 is a 360 by 1 colormap matrix.
colorbar; % Show a colored ramp showing what intensities map to what RGB color.
  댓글 수: 2
Saba Malik
Saba Malik 2016년 5월 13일
Hi - thanks for your reply
My issue is actually getting to the image stage from the values I have in the matlab file . You said 'display your grayscale image' but I wouldn't be able to do that until I generate a colormap from the RGB values in the file
Image Analyst
Image Analyst 2016년 5월 14일
You said you have "a 360 x 3 matrix of double RGB values" - well, that is the exact format that a colormap would take. Is the matrix not a colormap? If no, then what is it?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by