Filter löschen
Filter löschen

How do I tune a color scale to a matrix image?

1 Ansicht (letzte 30 Tage)
Shang Gao
Shang Gao am 18 Sep. 2018
Kommentiert: jonas am 23 Sep. 2018
Hi, I have a problem with my other programming tool and have to use MatLab to draw a 2D map with the specific color scale. The function is basically like mat2gray(), only difference is that instead of the gray color scale, I need it to be like the color scale in the image attached.

Akzeptierte Antwort

jonas
jonas am 18 Sep. 2018
Bearbeitet: jonas am 18 Sep. 2018
You can easily draw your matrix with a specific colormap. You don't need to convert it to an image beforehand.
A=peaks;
imagesc(A);
colormap(bone);
If you then want the image data, you can just type
I = getframe;
and then you can treat is as an image
imshow(I.cdata)
  3 Kommentare
jonas
jonas am 22 Sep. 2018
Bearbeitet: jonas am 22 Sep. 2018
It was just an example. Just stack the colors of a single column of your colorscale and use it as colormap. If I is the RGB matrix of your colorbar, then I(:,1,:) contains the RGB triplets of your colormap. Just reshape it from nx1x3 to a nx3 matrix.
Can give you code in a bit if you dont figure it out. On mobile atm.
jonas
jonas am 23 Sep. 2018
Here you go
A=peaks;
imagesc(A);
I=imread('image.png')
cmap=im2double([I(:,1,1) I(:,1,2) I(:,1,3)])
colormap(cmap);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by