Converting a RGB image to Gray scale in Ocatve

In this we use octave to read RGB image and convert it into gray. This procedure is as follows:

1.Firstly read the image to RGB matrix (IMG,MAP,ALPHA).

2.Convert RGB Image to color- indexed image using rgb2ind().

3.Convert the color-indexed image to Gray-intensity image using  ind2gray(x,map).

4.Treat the border of gray matrix to fit in unit8 boundaries. You can use unit16 according to alpha.

(y = uint8((255 * y) / max(max(y)));)

5. you can skip above  4th step.

octave:1> [img,map,alpha]=imread(“/home/manpreet/Downloads/pic.jpg”);

octave:2> [x,map]=rgb2ind(img);

octave:3> y=ind2gray(x,map);

octave:4> imshow(y, map=”gray”);


// single function to convert RGB image to Gray

octave:1> img=imread(“/home/manpreet/Downloads/pic.jpg”);


octave:3>img_gray = rgb2gray(img);  // assign converted image to another that original image can’t effect.



octave:6>imwrite(img_gray); //save image


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s