negative values in matrix to show in white
5 views (last 30 days)
Show older comments
hello,
I have a matrix, where I changed certain values (row 23-30, columns 25-30) to -10.Now I have to display these negative values in white. How should I approach that? thanks
Kay
0 Comments
Accepted Answer
Image Analyst
on 20 Feb 2012
Here's one way:
matrixForDisplay = originalMatrix; % Initialize a copy.
negativeIndexes = originalMatrix < 0;
matrixForDisplay(negativeIndexes) = max(originalMatrix);
imshow(matrixForDisplay, []);
That's one way, which will work even for floating point images. it will scale the max of your array to 255 and negative values will also be set to the max and so will also show up as 255. The lowest value after the negative values have been changed to the max (say, perhaps it's 3 or 5 or something) will display as 0 (black).
2 Comments
Walter Roberson
on 20 Feb 2012
I would suggest max(originalMatrix(:))
Note that the behavior of the above code will depend upon the colormap that is in effect.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!