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 Kommentar

Adam
Adam am 18 Jul. 2017
Bearbeitet: Adam am 18 Jul. 2017
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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jan
Jan am 18 Jul. 2017
Bearbeitet: Jan am 18 Jul. 2017

0 Stimmen

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.

Weitere Antworten (0)

Gefragt:

am 18 Jul. 2017

Bearbeitet:

Jan
am 18 Jul. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by