How to convert RGB image to grayscale image

4 views (last 30 days)
Please help me to convert RGB image to grayscale without using rgb2gray().

Accepted Answer

Image Analyst
Image Analyst on 2 Feb 2014
Sounds like homework. You can get the color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
and then do a weighted average of them.
grayImage = a1 * redChannel + a2 * greenChannel + a3 * blueChannel;
Look up standard weights, or pick your own.
  3 Comments
DGM
DGM on 30 Nov 2021
What's wrong with just giving the luma constants?
[0.299 0.587 0.114] for Rec 601 (what rgb2gray() uses)
or
[0.2126 0.7152 0.0722] for Rec 709

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!