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 commentaire

Adam
Adam le 18 Juil 2017
Modifié(e) : Adam le 18 Juil 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.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 18 Juil 2017
Modifié(e) : Jan le 18 Juil 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.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by