how to convert 0-255 scale to 30-170 scale in a grayscale Image?

4 views (last 30 days)
I have a 112*112 matrix in matlab which I am plotting as a grayscale image. I am using imacesc for this purpose and the resulting image is on a normal grayscale image, 0-255. However, the results are not quite pronounced in this scale and I want to rescale my image on a scale of 30 - 170 since most of my pixel values are in this range. I am using rescale for this purpose but it is not working. Can anyone help me with this issue?

Accepted Answer

Image Analyst
Image Analyst on 19 Nov 2020
Try telling imshow() the display range:
imshow(grayImage, [30, 170]);
but rescale() should have worked also:
imshow(rescale(grayImage, 30, 170), []); % Use [] because I think rescale() returns a double.
  2 Comments
Umair Bashir
Umair Bashir on 19 Nov 2020
Thank You for your reply. i have tried both these functions but they are not having any effect on the pixel intensities, instead they're just chaning the colormap range.
Image Analyst
Image Analyst on 19 Nov 2020
Correct. If you actually want to change the gray scales, you'd use imadjust():
grayImage = imread('cameraman.tif');
subplot(1, 2, 1);
imshow(grayImage);
grayImage = imadjust(grayImage, [130, 170]/255, [0, 255]/255);
subplot(1, 2, 2);
imshow(grayImage);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!