negative values in matrix to show in white

5 views (last 30 days)
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

Accepted Answer

Image Analyst
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
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.
Kay
Kay on 20 Feb 2012
It worked! thank you both!

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!