Thursday, January 20, 2011

Matlab basics-2 : Format conversions in Matlab

Suppose we have an image

aa=imread("image.jpg");

Conversion to grayscale:

we can convert it to gray scale using the following operation

grayaa=rgb2gray(aa);

the matrix grayaa is the gray scale version of the image aa.

rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components:

0.2989 * R + 0.5870 * G + 0.1140 * B



Converting the image into black and white:

It can be done in various ways depending on the threshold values.

bw1=im2bw(aa); %% Converts the image into bw using a default value

bw2=im2bw(aa,i); %%here i lies between 0 and 1. 'i' having a value of 0.3 means a threshold value of nearly 77 ( 0.3*256).

An important observation here is that the input image aa can be a grayscale image, an intensity image or even a RGB image.

If we give a RGB image as an input, MATLAB converts the RGB to grayscale first and then into black and white by itself.

2 comments:

  1. nice information you shared here thanks for sharing this stuff here

    Khurram Shahzad
    computer LCD

    ReplyDelete
  2. I'm extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Anyway keep up the nice quality writing, it is rare to see a great blog like this one these days ..

    my web page; 부산오피


    ReplyDelete