imagesc an integer 2d array using particular colors

2 visualizaciones (últimos 30 días)
MatG
MatG el 16 de Ag. de 2017
Respondida: Walter Roberson el 16 de Ag. de 2017
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?

Respuestas (1)

Walter Roberson
Walter Roberson el 16 de Ag. de 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.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by