フィルターのクリア

How to fill a binary valued matrix with a specific color?

18 ビュー (過去 30 日間)
Deepa AS
Deepa AS 2015 年 7 月 31 日
編集済み: Deepa AS 2015 年 7 月 31 日
I have a binary matrix, my question is how to fill with some particular color say red in the regions having 1's and fill with some other color say green if the values are 0's.Is that possible? If so can anyone please help me out with this.
Thank you Deepa

採用された回答

Adam
Adam 2015 年 7 月 31 日
colour0 = [0 1 0];
colour1 = [1 0 0];
figure; hAxes = gca; imagesc( binaryMatrix )
colormap( hAxes, [colour0; colour1] )
That works for a binary matrix. If you wanted to do it for more values you would have to put a little more care into the creation of the colourmap, but since your question was on a binary matrix that solution should work.
  3 件のコメント
Image Analyst
Image Analyst 2015 年 7 月 31 日
Adam's code will make it red for 1's and green for 0's for display only. Just to expand on that a little, if you want to create an actual RGB matrix, like if you want to save it with imwrite() or something, then you can use
myColorMap = [0,1,0;1,0,0];
rgbImage = ind2rgb(binaryMatrix, myColorMap);
Deepa AS
Deepa AS 2015 年 7 月 31 日
編集済み: Deepa AS 2015 年 7 月 31 日
Thank you sir.That was helpful.Works fine.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by