问题
I am trying to implement an algorithm in computer vision and I want to try it on a set of pictures. The pictures are all in color, but I don't want to deal with that. I want to convert them to grayscale which is enough for testing the algorithm.
How can I convert a color image to grayscale?
I'm reading it with:
x = imread('bla.jpg');
Is there any argument I can add to imread
to read it as grayscale? Is there any way I change x
to grayscale after reading it?
回答1:
Use rgb2gray
to strip hue and saturation (ie, convert to grayscale). Documentation
回答2:
x = imread('bla.jpg');
k = rgb2gray(x);
figure(1),imshow(k);
回答3:
I found this link: http://blogs.mathworks.com/steve/2007/07/20/imoverlay-and-imagesc/ it works.
it says:
im=imread('your image');
m=mat2gray(im);
in=gray2ind(m,256);
rgb=ind2rgb(in,hot(256));
imshow(rgb);
回答4:
you can using this code:
im=imread('your image');
k=rgb2gray(im);
imshow(k);
using to matlab
回答5:
I=imread('yourimage.jpg');
p=rgb2gray(I)
回答6:
Use the imread()
and rgb2gray()
functions to get a gray scale image.
Example:
I = imread('input.jpg');
J = rgb2gray(I);
figure, imshow(I), figure, imshow(J);
If you have a color-map image, you must do like below:
[X,map] = imread('input.tif');
gm = rgb2gray(map);
imshow(X,gm);
The rgb2gray
algorithm for your own implementation is :
f(R,G,B) = (0.2989 * R) + (0.5870 * G) + (0.1140 * B)
来源:https://stackoverflow.com/questions/1779652/how-can-i-convert-a-color-image-to-grayscale-in-matlab