Customizing colourmap for display

14 ビュー (過去 30 日間)
Diptangshu Sen
Diptangshu Sen 2018 年 9 月 8 日
コメント済み: Walter Roberson 2018 年 9 月 9 日
I have a matrix consisting of only the following values, 0, 1 and 2. I want to visualize the matrix by using the following colour code, green for 0, yellow for 1 and red for 2. How do I go about doing this? Any help will be appreciated.

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 8 日
Cmap = [0 1 0; 0 1 1; 1 0 0];
image(uint8(YourMatrix)) ;
colormap(Cmap) ;
  2 件のコメント
Diptangshu Sen
Diptangshu Sen 2018 年 9 月 9 日
Thanks Walter for your speedy response. It works perfectly. But, could you elaborate on how you constructed the Cmap matrix and how I can extend it for a larger number of types of entries, 5 for example. Thanks in advance.
Walter Roberson
Walter Roberson 2018 年 9 月 9 日
You just need to create an N x 3 matrix. Each entry should be in the range 0 (off) to 1 (fully on). The first column is for Red, the second for Green, the third for Blue (RGB).
When you image() a uint8, uint16, uint32, uint64 , int8, int16, int32, or int64 matrix instead of a double matrix, then the value 0 is mapped to the first color, the value 1 is mapped to the second color, and so on.
The rules are slightly different if the values are double or single: in that case by default the value 1 is mapped to the first color, the value 2 is mapped to the second color, and so on.
This mapping does not apply if the image data is 3D.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by