Thursday, January 20, 2011

Matlab basics-2 : Format conversions in Matlab

Suppose we have an image


Conversion to grayscale:

we can convert it to gray scale using the following operation


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.

1 comment:

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

    Khurram Shahzad
    computer LCD