# Converting an RGB image to Gray Scale in MatLAB



## 060456F (Jun 27, 2008)

Hi,this is my first post in Digital Photography and Imaging forum in TSG. I'm following a module called "Image Processing" in my university. It has just begun and I'm a novice in this field. They don't want us to use a software like Photoshop to do processing. They want to go little deeper and to write programs to do the imaging tasks. They use MatLAB to the programming. I'm pretty familiar with MatLAB as I'm using it for couple of years.
Now we have been given an assignment to complete. One of the question in it is to write a code to convert an RGB image to gray-scale. We can do this using following code.

im = imread('image_name.jpg')
imgray = rgb2gray(im)
imshow(imgray)

qiet easy. But they don't wan't us to use rgb2gray function. So how can I do without it ?
ANybody know the Red, Green and Blue values for a monochrome (gray-scale) image.


----------



## CarolinaBill (Jan 1, 2006)

The RGB values can be varied but the saturation or intensity value for the individual pixels is the important value. If your pixel color is in 4-byte form, three of the bytes will give the amount of each color (varying from 0 to 255 or 0 to FF hex), while the fourth byte describes the saturation. If you change a pixel's saturation byte to 0 without changing the RGB values you will get a grayscale representation.


----------



## 060456F (Jun 27, 2008)

Thanks for the reply. Anyway I found the RGB values for the gray scale image in Matlab. It was in the help file. Matlab has an extensive support in its online help. It's help files are well structured, not like other software help files.


----------

