Tuesday 25 August 2015

converting True color RGB image into grayscale Image

In matlab there is a function rgb2gray() to convert rgb image into gray scale image.
we can do this manually also.


  1. rgb = imread('Sun.jpg');
  2. figure('name','Original Image')
  3. imshow(rgb);

  4. gray_manual = 0.2989 * rgb(:,:,1) + 0.5870 * rgb(:,:,2) + 0.1140 * rgb(:,:,3);
  5. figure
  6. imshow(gray_manual);

Output
Original Image

Converted GrayScale Image
Formula to do this is
Intensity = 0.2980 * red + 0.5870 * green + 0.1140 * blue


Matlab Image Processing

I am trying to do learn image processing using matlab..
I find tutorials here http://www.bogotobogo.com/Matlab/Matlab_Tutorial_Digital_Image_Processing_2_RGB_Indexed_Color_Info.php

Below program explains converting true color rgb image into index image and show the difference between mapping the index image into various levels.

code
  1. image = imread('Sun.jpg');
  2. figure('name','Original Image')
  3. imshow(image);

  4. [IND,map] = rgb2ind(image,32);
  5. figure('name','image with 32  index')
  6. imshow(IND),colormap(map);

  7. [ind_132,map_132] = rgb2ind(image,132);
  8. figure('name','image with 132 index')
  9. imshow(ind_132),colormap(map_132);
you can also found that sum image on the above link or here 

results
Original Image

Image with 32 Index
Image with 132 Index