views:

329

answers:

5

sorry but i need help how to differentiate between circle rectangle and triangle in black and white images-bitmaps-

+7  A: 

Circles are round; triangles have three sides; rectangles have four sides intersecting at right angles.

James McNellis
+1, very relevant and to the point
Rik
yes but how to tell the pc that
new programer
@new programmer: by writing code accordingly.
BalusC
A: 

If noise is low enough to extract curves, approximations can be used: for each shape select parameters giving least error (he method of least squares may help here) and then compare these errors...

If the image is noisy, I would consider Hough transform - it may be used to detect shapes with small count of parameters, like circle (harder for rectangles and triangles).

maxim1000
the images are noisy, and i have a training set for each shape
new programer
A: 

Hi,

just an idea off of the top of my head: scan the (pixel) image line-by-line, pixel-by-pixel. If you encounter the first white pixel (assuming it has a black background) you keep it's position as a starting point and look at the eight pixels surrounding it in every direction for the next white pixel. If you find an adjacent second pixel you can establish a directional vector between those two pixels.

Now repeat this until the direction of your vector changes (or the change is above a certain threshold). Keep the last point before the change as the endpoint of your first line and repeat the process for the next line.

Then calculate the angle between the two lines and store it. Now trace the third line. Calculate the angle between the 2nd and 3rd line as well.

If both angles are rectangular you probably found a rectangle, otherwise you probably found a triangle. If you can't find any straight line you could conclude that you found a circle.

I know the algorithm is a bit sketchy but I think (with some refinement) it could work if your image's quality is not too bad (too much noise, gaps in the lines etc.).

andyp
+1  A: 

You are looking for the Hough Transform. For an implementation, try the AForge.NET framework. It includes circle and line hough transformations.

Wim Coenen
+2  A: 

You could train an Artificial Neural Network to classify the shapes :P

Manuel