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
0 个评论
回答(2 个)
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
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
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
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 Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!