Grayscale in matlab

限于喜欢 提交于 2019-12-25 04:55:48

问题


I'm trying to convert a 2D array to grayscale but using mat2gray doesn't do anything and imshow() appears to create a binary image that when I graph I cannot rotate it, e.g. the original array is 2d but maps in 3d. So, what is the best way to take a grayscale of 2d array in Matlab so if you have A=rand(5,10) or something and want to take a grayscale of that, what is the best way?


回答1:


I would expect MAT2GRAY to work, but if it doesn't you can try this:

A = rand(5,10);     %# Make a random array of values between 0 and 1
B = uint8(255.*A);  %# Scale the values and convert them to uint8



回答2:


If you use imshow on a 2D image, it is a good idea to use autoscaling.

img = randn(100);
imshow(img,[]);


来源:https://stackoverflow.com/questions/2954600/grayscale-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!