문제

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?

도움이 되었습니까?

해결책

Use rgb2gray to strip hue and saturation (ie, convert to grayscale). Documentation

다른 팁

x = imread('bla.jpg');
k = rgb2gray(x);
figure(1),imshow(k);

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);

you can using this code:

im=imread('your image');
k=rgb2gray(im);
imshow(k);

using to matlab

I=imread('yourimage.jpg');
p=rgb2gray(I)

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top