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 Commento

Adam
Adam il 18 Lug 2017
Modificato: Adam il 18 Lug 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.

Accedi per commentare.

 Risposta accettata

Jan
Jan il 18 Lug 2017
Modificato: Jan il 18 Lug 2017
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.

Più risposte (0)

Richiesto:

il 18 Lug 2017

Modificato:

Jan
il 18 Lug 2017

Community Treasure Hunt

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

Start Hunting!

Translated by