Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Image processing -----Color detection.

Status
Not open for further replies.

iVenky

Advanced Member level 2
Joined
Jul 11, 2011
Messages
584
Helped
37
Reputation
76
Reaction score
35
Trophy points
1,318
Location
College Station, Texas
Activity points
6,124
I want to detect the color and it's position in an image. I don't get the output. I would be really happy if you could guide me.
Example: Take a red box in a white background at some position. I want to detect the red color and it's position (i.e. co-ordinates) in the image
 

Hi friend;
For white background all R,G,B components should have the value of "1".
But for the red box, only R component should have values close to "1" and other color component should be "0".
So you can pick a pixel and search the rule below.
if at any pixel, (R component is close to 1) and (G component close to 0) and (B component close to 0)
then that is red color point.
And pixel index will give you the location information of red color.

Hope, it gives idea.
Good luck.
 

I have another problem too.
I am trying to move my bot to the corresponding color in the image. I tried some algorithms but it didn't work out. I would be really happy if you could help me with this thing. I would be much obliged if you could provide me some kind of sample code or something. If you have this code please share the code with me.
Here's the image https://picasaweb.google.com/113606847351479489219/January142012#5697511886387683426

I am trying to move my bot to the black rectangle corresponding to the red.

The robot is in the black circle at the bottom. I need to move the robot to the left. I don't have problem with the serial communication. The problem is with the image processing part code. I would be really happy if you could help me.

I need the robot to move to the position of the black square near the red one. For that I want to first detect where the red square is. After that using left,right,up and down direction commands (i.e. serial data corresponding to left, right, up and down) the robot has to go to that position.

Assume that

left- 00, right- 01, up- 10, down-11

I know how to do the serial communication using Matlab.

So there's no need of the code for serial communication. Let's assume that out(a) will send the value contained in 'a' serially (a has the value for direction - 00 or 01 or 10 or 11).

All I need is the algorithm

Thanks in advance
 

Hi iVenky;
I can't do all staff you mention.
But here i do some simple coding which defines red areas in the image (see attcahed pic, red areas are in white, others are black).
red_areas.jpg
You can see the Matlab code below, where [x,y] contains the red points indices. You can generate necessary coordinates.
Code:
im=imread('image.jpg');
imshow(im);

figure
imshow([im(:,:,1) im(:,:,2) im(:,:,3)])

R_th=245;
G_th=15;
B_th=15;

%a red point is (r,g,b)=(1,0,0)
R=double(im(:,:,1)>R_th); %if red assign '1'
G=double(im(:,:,2)<G_th); %if green assign '0'
B=double(im(:,:,3)<B_th);

im2(:,:,1)=R;
im2(:,:,2)=G;
im2(:,:,3)=B;

%define red points
reds=sum(im2,3);
red_im=double(reds==3);

%store red point indices
[x,y]=find(red_im);

figure
imshow(red_im)

Hope helps you
Good luck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top