Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Color Thresholding

Subject: Color Thresholding

From: Cory

Date: 21 Oct, 2010 17:38:04

Message: 1 of 5

I am trying to threshold an image based on RGB color. I know what i want the min/max for the image to be thresholded to but I am unsure if there is a direct function for thresholding an image based on color instead of grayscale. Any help is appreciated.

Subject: Color Thresholding

From: Sean

Date: 21 Oct, 2010 17:49:03

Message: 2 of 5

"Cory " <cory.hayes@gkndriveline.com> wrote in message <i9ptps$mtg$1@fred.mathworks.com>...
> I am trying to threshold an image based on RGB color. I know what i want the min/max for the image to be thresholded to but I am unsure if there is a direct function for thresholding an image based on color instead of grayscale. Any help is appreciated.

Sure, just threshold that channel

Rchannel = I(:,:,1);
Gchannel = I(:,:,2);
Bchannel = I(:,:,3);

Map = Gchannel(Gchannel>thresh); %thresholding green

I = bsxfun(@times,I,uint8(Map)); %apply map to whole image

Subject: Color Thresholding

From: Cory

Date: 21 Oct, 2010 18:31:03

Message: 3 of 5

> Map = Gchannel(Gchannel>thresh); %thresholding green

This is giving me a one column array, so that when I try and use bsxfun I am getting an error since I and Map are not the same dimensions...

> I = bsxfun(@times,I,uint8(Map)); %apply map to whole image

Subject: Color Thresholding

From: Sean

Date: 21 Oct, 2010 18:40:05

Message: 4 of 5

"Cory " <cory.hayes@gkndriveline.com> wrote in message <i9q0t7$d6d$1@fred.mathworks.com>...
> > Map = Gchannel(Gchannel>thresh); %thresholding green
>
> This is giving me a one column array, so that when I try and use bsxfun I am getting an error since I and Map are not the same dimensions...
>
> > I = bsxfun(@times,I,uint8(Map)); %apply map to whole image

Sorry should just be:
Map = Gchannel>thresh;

Subject: Color Thresholding

From: ImageAnalyst

Date: 21 Oct, 2010 18:43:33

Message: 5 of 5

On Oct 21, 1:38 pm, "Cory " <cory.ha...@gkndriveline.com> wrote:
> I am trying to threshold an image based on RGB color. I know what i want the min/max for the image to be thresholded to but I am unsure if there is a direct function for thresholding an image based on color instead of grayscale. Any help is appreciated.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Yes, of course. Check out my color detection demos at:
http://www.mathworks.com/matlabcentral/fileexchange/authors/31862

(Also get the histogram shaping demo if you also want a nice
thresholding GUI)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us