Locate rectangles in an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pitosalas

Locate rectangles in an image

Post by pitosalas »

I have an image of a form or ballot: http://www.salas.com/elect/testballot1.tif

I've been working out how to analyze it. My next challenge is to locate 'rectangles' on it. What I mean is a rectangle with a thin black outline, and the inside primarily white (i.e. white or grey with more black marks inside, but mostly white.) The rectangles are fully closed.

On the sample tif above, I see 23 rectangles. Some have a white background and some have a grey background. Perhaps each kind of rectangle will require a different technique to locate.

The output I would like is an array of rectangle coordinates, top, left, width, height, one for each of the 23.

Any tips, suggestions or pointers, would be greatly appreciated!!

Thanks

Pito
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Locate rectangles in an image

Post by anthony »

What you need to do is locate the center of just the corner 'dots'. When you have those, distort the image to move those dots to a fixed 'known' location. After distortion, ALL the other 'rectangles' will be very close to or at least within 'known' and pre-configured coordinates.

All that you need to do then is to 'crop' the area of each of the coordinates, blur and threshold
to remove any 'noise' and then see if their a a strong black mark within that area. If present
the user marked it. Otherwise they did not.

So the trick comes down to locating the 'corner' dots.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply