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


No comments:

Post a Comment