How to reproduce imshow display range [] ?

23 ビュー (過去 30 日間)
Arianna FS
Arianna FS 2019 年 3 月 10 日
回答済み: Image Analyst 2019 年 3 月 10 日
Hi
having a grayscale image (f.e. "img", 512x512, double), how can one reproduce the scaling that is done by imshow(img, []) and save the result?
From the Mathworks documentation I know that ..."If you specify an empty matrix ([]), imshow uses [min(I(:)) max(I(:))]"...
I tried using imadjust as imadjust(img, [min(img(:))/255, max(img(:))/255], [0, 1]), but this didn't work as it gave a different ouput than the imshow function.
Thanks already in advance!

回答 (2 件)

Walter Roberson
Walter Roberson 2019 年 3 月 10 日
mat2gray() rescales between the min and max values. Not the most obvious of routine names.
Since R2017b there has also been rescale()

Image Analyst
Image Analyst 2019 年 3 月 10 日
Why are you using imadjust()? You can just use max and min to save the display range:
displayMin = min(img(:));
displayMax = max(img(:))
% Display img:
imshow(img, []); % Will use [displayMin, displayMax]
% Display image1 using same display range as img.
imshow(image1, [displayMin, displayMax]);
% Display image2 using same display range as img.
imshow(image2, [displayMin, displayMax]);
% etc.

Community Treasure Hunt

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

Start Hunting!

Translated by