imagesc an integer 2d array using particular colors

4 views (last 30 days)
I would like to draw a 2d array of integers whose values are only from the set {11,12,21,22,23,24,31,41,42,43,51,52,71,72,73,74,81,82,90,95} using the corresponding colors in the figure below (attached). For instance dark red for 24 and yellow for 81 as can be seen from the figure. How can I do this in MATLAB?

Answers (1)

Walter Roberson
Walter Roberson on 16 Aug 2017
Construct a color map that has at least 95+1 entries, and store the RGB corresponding to integer N at row N+1; for example, put the entry corresponding to color 52 in row 53 of the color map. You can put any handy thing into the other entries (e.g. 0 0 0)
Then you can either
image( uint8(YourArray) );
colormap( TheColorMap );
or
imshow( uint8(YourArray), TheColorMap );
There are other ways as well, but the above ways easily preserve the values that will show up if you use the data cursor.
The reason for adding 1 is that when you using uint8(), the value 0 corresponds to the first entry, the value 1 corresponds to the second entry, and so on.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!