Extract color of image

I want to extract red part and green part of attached image. I want to extract Red part is to one image and green part is to next image. Please help me.

Answers (3)

IM = imread('red_rose.jpeg');
R_only = IM;
R_only(:,:,[2 3]) = 0;
imshow(R_only);
pause;
G_only = IM;
G_only(:,:,[1 3]) = 0;
imshow(G_only);

2 Comments

PK
PK on 11 Oct 2016
Thanks for your answers. I want to extract only green leaves photo and only red flower photo.
Search the Answers forum for the word "leaf"

Sign in to comment.

SREERAG k
SREERAG k on 21 Nov 2017

0 votes

how can i identify a picture uploaded is a leaf or not

6 Comments

Could be pretty tricky, considering all the various shapes and colors of leaves out there. Some leaves are as small as 1 mm; some are over 50 m^2 in area.
SREERAG k
SREERAG k on 24 Nov 2017
Moved: DGM on 12 Feb 2023
how can i check whether a image has 50 per green color
Walter Roberson
Walter Roberson on 24 Nov 2017
Moved: DGM on 12 Feb 2023
First you have to define what it means for a color to be "green". See https://blog.xkcd.com/2010/05/03/color-survey-results/ for partial information on differences in how some people define green.
I take it you did not look at the pictures of leaves that I linked to, as that shows clearly that leaves do not need to be green.
There is a Blue Spruce, Picea pungens, at the end of the next block over from me. Lovely tall tree, but you would not call the leaves green.
SREERAG k
SREERAG k on 24 Nov 2017
Moved: DGM on 12 Feb 2023
actually we have a constrain that we only take green leaves .At the initial stage we would like to test only on green leaves
Guillaume
Guillaume on 24 Nov 2017
Moved: DGM on 12 Feb 2023
@Sreerag k,
The boxes you're using to ask your questions are clearly marked Answer this question. You're not answering a question, so please stop spamming other people questions with your own and start your own question.
Walter Roberson
Walter Roberson on 24 Nov 2017
Moved: DGM on 12 Feb 2023
Please stop posting your responses as new Answers. Instead, click on one of the "Comment on this Answer" links to add the information there.
You have to define what it means for a color to be "green". See https://blog.xkcd.com/2010/05/03/color-survey-results/ for partial information on differences in how some people define green.
When I say you have to define what it means for a color to be green, I mean that you need to give us rules that allow us to test any given RGB pixel and determine Yes, or No, "Does this color count as green?". It has to be able to make firm decisions. For example, does RGB [0, 1/255, 0] count as "green", or does it count as "black" ? Does [242/255, 255/255, 242/255] count as "green" but [252/255, 255/255, 252/255] counts as "grey" ? If the green channel is full intensity, then exactly what is the maximum that the R and B channels can be set to and still have the color count as "green"? We need hard rules with all of the boundary conditions described, not just the word "green".

Sign in to comment.

Yushuo
Yushuo on 28 Jun 2022
Edited: Yushuo on 28 Jun 2022

0 votes

I use the attached code to extract red color (it use LAB color, you can change the LAB value of the color you want in LMean aMean bMean) and you can change the tolerance as well. Parts code from https://se.mathworks.com/matlabcentral/fileexchange/31118-color-segmentation-by-delta-e-color-difference

Asked:

PK
on 11 Oct 2016

Moved:

DGM
on 12 Feb 2023

Community Treasure Hunt

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

Start Hunting!