How do I map an array to grayscale colormap?

11 次查看(过去 30 天)
I have an array of numbers and would like to:
1) map 0 to a display intensity of 0 and the highest value in the array to white with a display intensity of 255, with the numbers of the array in between mapped to display between the grayscale range 0-255.
2) map the median number in the array to display an intensity of 255, with anything higher than the median number being displayed with an intensity of 255, and anything lower than the median number being displayed with a pixel intensity between 0-255.
I think I might have 1) figured out if just using colormap('gray') automatically gives the highest number in the array the brightest intensity, but in my image I dont see anything bright white, just shades of gray.

采纳的回答

Walter Roberson
Walter Roberson 2013-8-26
1)
maxv = max(YourArray(:));
mapped_array = uint8((double(YourArray) ./ maxv) .* 255);
image(mapped_array);
colormap(gray(255));
2)
maxv = median(YourArray(:));
mapped_array = uint8((double(YourArray) ./ maxv) .* 255);
image(mapped_array);
colormap(gray(255));

更多回答(1 个)

Image Analyst
Image Analyst 2013-8-26
For #1, if you have the Image Processing Toolbox, you can simply do
imshow(grayImage, [0, max(grayImage(:)]);
You can get even more contrast if the image's lowest value is not zero by doing this:
imshow(grayImage, []);
For #2, it's similar:
imshow(grayImage, [0, median(grayImage(:)]);
These methods do not change grayImage (your original image) nor do they necessitate the creation of a temporary image used only for display.
  5 个评论
Walter Roberson
Walter Roberson 2013-8-28
In general, the default colormap size is 64 entries; I do not have IPT so I do not know what imshow() would do.
Image Analyst
Image Analyst 2013-8-28
The numbers in the brackets take the left number and make that 0 in the display, and the right number and make that show up as 255 and linearly scaled over the 254 gray levels in between. If it's [] then it sends the min of the image to 0 and the max of the image to 255.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by