How mat2gray work in matlab and How can I scale image using mat2gray as the format, 0 for max value and 255 for min value?

조회 수: 16 (최근 30일)
first of all i want to know how mat2gray works ?. i mean back end work and formula etc. then i want scale the image using it so that it follows the format, 0 for max value and 255 for min value.
Thanks

답변 (2개)

Guillaume
Guillaume 2017년 7월 8일
You can look at the code of mat2gray and understand how it works by typing
edit mat2gray
at the command line. You'll find that it works exactly as explained in the documentation.
As for your other question, 0 for max value and 255 for min value, unfortunately for you, matlab follows the same mathematical rules as everybody else, where 0 < 255. You will have to write your own version of matlab if you want 255 < 0 (or a different definition of min and max). Perhaps if you explained your ultimate goal we may understand better why you ask such a question.

Image Analyst
Image Analyst 2017년 7월 8일
I'm not sure what " 0 for max value and 255 for min value" means, but you can invert your image like this:
invertedGrayImage = 255 - grayImage;
What used to be the max will now show up as 0 and imshow() will show it as dark/black.
Alternatively, you could use a colormap, which doesn't change the image or create a new one, it changes the way it appears upon display
imshow(grayImage); % Scale min to max
colormap(gca, flipud(gray(256)));
mat2gray scales the min to 0 and the max to 255, no matter where they started. To create a new array where the min starts at 0 and the max gets mapped to 255, do this:
uint8Image = uint8(255 * mat2gray(grayImage));
  댓글 수: 23
Image Analyst
Image Analyst 2020년 1월 28일
Yes, I agree with Guillaume. And attach your image file and answer my question above about why you can't just work with the original values.
Raka Mukherjee
Raka Mukherjee 2020년 1월 29일
Yes sure. I am starting my own question and attaching the images as well. I am quite new to MATLAB and more new to work with the colour component of images so I am not quite sure whether we can work with a 16 bit data to find out particular colour (say,gray) from images as it is easier to work with 8 bit data. The images are Landsat Red, Green and Blue bands which have a depth of unsigned 16 bit.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by