MATLAB Answers

## how to detect red color

Asked by Tulips

### Tulips (view profile)

on 21 Feb 2012
Latest activity Edited by Cedric Wannaz

### Cedric Wannaz (view profile)

on 22 Oct 2013
Accepted Answer by Sukuchha

### Sukuchha (view profile)

hi, i want to ask how to detect red color for the circlar shape(blue color) in this image. can someone tell me the step? thanks. how to separate the color band? i dont underrstand how to declare the arrays?

http://www.flickr.com/photos/77154085@N06/?saved=1 I want to know how to get the shape circle with white color and the background is in black color. it means the arrow in the circle will be black color but the circle will be white color. the other background is black.how to do blue segmentation to get threshold image?i mean color threshold. can u tell me the step. i need it absolutely. plz help me!

## Products

No products are associated with this question.

## 4 Answers

### Sukuchha (view profile)

Answer by Sukuchha

### Sukuchha (view profile)

on 21 Feb 2012
Accepted answer

A = imread('http://farm8.staticflickr.com/7192/6915806857_cfb9d98996_m.jpg');
imshow(A,[])
B= A(:,:,3); % your blue band!

you can do morphological operation to get the circle !

Tulips

### Tulips (view profile)

on 21 Feb 2012

no..i mean how to detect the only circle shape of binary in white color but the background is in black color

Sukuchha

### Sukuchha (view profile)

on 21 Feb 2012

use regionprops with eccentricity property.

circles have close to 0 eccentricity

Tulips

### Tulips (view profile)

on 21 Feb 2012

can u show the code as im a newbie in matlab:(. do i need to separate the color band using looping?

### Image Analyst (view profile)

Answer by Image Analyst

### Image Analyst (view profile)

on 21 Feb 2012

Rose, see my color segmentation demos: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Looks like you already marked the situation as solved. If you have any additional questions, other than this, just ask again.

Jan Simon

### Jan Simon (view profile)

on 23 Feb 2012

Shorter: A = 255 * (A > 50)

Tulips

### Tulips (view profile)

on 23 Feb 2012

i just want to detect the shape only in white color . the background will be white.thats all.which part shud I re-edit

Image Analyst

### Image Analyst (view profile)

on 23 Feb 2012

That code you posted is, well, let's say naive and not very robust or flexible, at best. Rose, you don't need to understand the code just to run it. Once you see that it works, you can take it line by line. It's not that hard. I just explained it to a chemist a half hour ago and she totally got it. A smart engineer like you should have no problem with well commented demo code like I always write.

Answer by Tulips

### Tulips (view profile)

on 21 Feb 2012

im sorry abt the question i have asked. i am asked to detect the blue color. i mean the circle shape.

Jan Simon

### Jan Simon (view profile)

on 21 Feb 2012

You can edit the question. This is much better than appending an "answer", which is no answer.

Tulips

### Tulips (view profile)

on 21 Feb 2012

Simon do have any idea?

### Image Analyst (view profile)

Answer by Image Analyst

### Image Analyst (view profile)

on 25 Feb 2012

Rose, let me ask you again to run my delta E app on your image. I just did right now and it did a nearly perfect job of getting the blue sign. You just need to do a hole fill to fill in some of the little white glints and tears on the sign. Why are you being so reluctant to run it? It's very simple. It just asks you to open your image and draw some part of the image that has the color you want to find. It doesn't even have to be all of the color, just some of the pixels with that color. Then it asks you for a number to say how close to that color do you want to find. It even suggests a good tolerance number for you. Then it finds them all. It can't get much easier. I don't know what else to suggest when something like I've already provided works so perfectly, unlike the other answer you accepted. Again, try it and you'll see.

http://www.mathworks.com/matlabcentral/fileexchange/31118-color-segmentation-by-delta-e-color-difference

Tulips

### Tulips (view profile)

on 29 Feb 2012

thank you sir, u really help. need to study the algortihm more. and i want to know, to detect either red , blue or yellow color , the threshold range for hue, saturation and value must be set after we did RGB2HSV conversion. in ur code that u hv showed u just only did yellow color detection. so i want to know what is the range of hue,saturate and value of threshold in order to detect either red or blue. is it same with ur coding or not?

Tulips

### Tulips (view profile)

on 29 Feb 2012

i simply didnot understand the deltaE app coding to detect blue color? can u help by giving me explanation?

Tulips

### Tulips (view profile)

on 29 Feb 2012

based on delta E app. it need Lab . instead of using Lab channel color, can i rgb2hsv conversion to detect blue or red color? im sorry if i have asked u multiple question:(

#### Join the 15-year community celebration.

Play games and win prizes!

Learn more

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

### MATLAB Academy

New to MATLAB?

Learn MATLAB today!