Assign User-defined grayscale value

I have data in matrix form and I want to assign elements in matrix specific grayscale value( 8-bit, 0 to 256) and than plot a 2D Grayscale image. The function 'mat2gray' assign 0 value to minimum and 1 to maximum but I want to have user-defined value given to elements. [for ex. if my element value is 50 I want to assign grayscale value of 0 to it irrespective whether its minimum or maximum]

1 件のコメント

Adam
Adam 2017 年 7 月 18 日
編集済み: Adam 2017 年 7 月 18 日
Just create your own mapping or colourmap then. mat2gray is just a convenience function for the trivial maths of max stretching a data range to the full colourmap range.

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

 採用された回答

Jan
Jan 2017 年 7 月 18 日
編集済み: Jan 2017 年 7 月 18 日

0 投票

Create a lookup table:
LUT = zeros(1, 256);
LUT(50 + 1) = 1;
Img = randi([0, 100], 200, 100); % Your image
Grey = LUT(Img + 1);
Now the pixels of Img with the value 50 are set to 1.0, and all others to 0.0 . Of course you can adjust LUT arbitrarily.

その他の回答 (0 件)

質問済み:

2017 年 7 月 18 日

編集済み:

Jan
2017 年 7 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by