How can I convert a color image to grayscale in MATLAB?

Nathan Fellman picture Nathan Fellman · Nov 22, 2009 · Viewed 56.6k times · Source

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?

Answer

Donnie picture Donnie · Nov 22, 2009

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