MATLAB Answers

Convert an RGB image to grayscale but keep one color?

35 views (last 30 days)
Jaja
Jaja on 7 Sep 2014
Commented: Image Analyst on 25 Sep 2014
A = imread('C:\FFOutput\gdgf\B.jpg'); B = rgb2gray(A); figure(1),imshow(B);
I have converted the image to a grayscale but don't know how to keep one color especially green.

Answers (3)

yonatan gerufi
yonatan gerufi on 7 Sep 2014
Edited: yonatan gerufi on 7 Sep 2014
Hi, there are several ways to do it,
i find it easy to do:
red_color = A(:,:,1);
green_color = A(:,:,2);
blue_color = A(:,:,3);
  1 Comment
Jaja
Jaja on 7 Sep 2014
how can I add this to my code to keep the green one? can you give me an example with the code??

Sign in to comment.


John
John on 7 Sep 2014
I am guessing you want the green channel stored in a separate matrix. In your code, A is only read. Its value does not change after the call to rgb2gray. To get the green channel from A:
greenChannel = A(:,:,2);
  1 Comment
Jaja
Jaja on 7 Sep 2014
nothing happens actually. can you give me an example with the code??

Sign in to comment.


Image Analyst
Image Analyst on 7 Sep 2014
  3 Comments
Image Analyst
Image Analyst on 25 Sep 2014
Why? That's pretty much what the original image is already.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by