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?
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.
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.
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.
you can using this code:
im=imread('your image');
k=rgb2gray(im);
imshow(k);
using to matlab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With