Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 546
Nathan Fellman Avatar asked Nov 22 '09 19:11

Nathan Fellman


People also ask

How do you make an image gray in Matlab?

I = mat2gray( A , [amin amax] ) converts the matrix A to a grayscale image I that contains values in the range 0 (black) to 1 (white). amin and amax are the values in A that correspond to 0 and 1 in I . Values less than amin are clipped to 0, and values greater than amax are clipped to 1.

How do I convert a RGB image to grayscale?

You just have to take the average of three colors. Since its an RGB image, so it means that you have add r with g with b and then divide it by 3 to get your desired grayscale image. Its done in this way.

What is grayscale in Matlab?

A grayscale image is a data matrix whose values represent intensities of one image pixel. While grayscale images are rarely saved with a colormap, MATLAB uses a colormap to display them. You can obtain a grayscale image directly from a camera that acquires a single signal for each pixel.


1 Answers

you can using this code:

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

using to matlab

like image 65
Dian Permata Avatar answered Nov 03 '22 00:11

Dian Permata