circle detection

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
daffy

circle detection

Post by daffy »

i am new to imagmagick and would like to know if there is any way to detect circle from following image.

i have posted this twice and somehow my account gets delete immediately!!

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle detection

Post by fmw42 »

This is not an easy problem. The best approach is a circle Hough transform. But IM has neither linear nor circular Hough transforms.

Best bet is to try working with edge detection and contrast and noise filtering. See -convolve or -morphology convolve at
http://www.imagemagick.org/Usage/convolve/

and

-edge at http://www.imagemagick.org/script/comma ... ek6l6#edge
daffy

Re: circle detection

Post by daffy »

i tried using circle Hough transform using emgu, but just cant get the circle detected.

i might need to process the image a bit, but dont know what operation will make visible the circle.
http://www.emgu.com/wiki/index.php/Main_Page
dproc
Posts: 19
Joined: 2010-09-14T20:39:15-07:00
Authentication code: 8675308

Re: circle detection

Post by dproc »

If the circles are always the same size and shape, or a small set of sizes, then you might just edge detect and clean things up like fmw42 said, but then just cross-correlate with a known good sample(s) that were also edge-detected and cleaned up. You might also try it without edge detection if the images of the objects are usually similar.
daffy

Re: circle detection

Post by daffy »

thanks for the info.
I will try to get the edges with it and see how that goes.

also, once i have the circle edge detected, is there a way to split say an image with 2 such circles into two distinct images ?

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

Re: circle detection

Post by anthony »

Once you have the circles, you can mask out those areas and extract them from the original (or cleaned) image.

That is purely composition masking.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
daffy

Re: circle detection

Post by daffy »

could you please guide me to appropriate example for composition masking.
i am surely not an image processing expert, so need some input or example if possible.

thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle detection

Post by fmw42 »

see http://www.imagemagick.org/Usage/layers/#convert and http://www.imagemagick.org/Usage/compose/#compose


But why do you need image composition for circle detection?

If you want to do things manually, you can measure the center of the circle and a point on the perimeter of the circle and just draw a red circle over your image. see -draw http://www.imagemagick.org/Usage/draw/#circles the circle can be transparent in the middle and just red or some color on its perimeter.
daffy

Re: circle detection

Post by daffy »

actual scenario is,
i have scanned image with a rectangle block (fix size) with bunch of holes (fix size, diameter).
what i am trying to do is, determine each hole distinctly
e.g. if i have 15 holes (5 in each row), i need some way to split them apart from original image and identify them uniquely ..like say

A > 0, 1, 2, 3, 4
B > 5, 6, 7, 8, 9
C > 10, 11, 12, 13, 14

so in about case i will have A0, A1, ....to C14

i am sure there is better way of doing it, but i am just not that savvy in this field.

any help would be appreciated.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle detection

Post by fmw42 »

can you post a link to your image? I am not sure what you mean by split them apart and identify them? Identify them in what way?
daffy

Re: circle detection

Post by daffy »

Image

i have upload image with 4 circles
so here i take top left corner as start and label it as A then that row contains two columns
and row under it i call it say B

A | 0, 1
B | 2, 3

so in that above image top row is A and bottom is B, first column start at index say 0 and it goes upto 3 to make total of 4 circles.

so i want to identify A0, A1, A2, A3 by splitting them from this original image such that, if i have A3 image with me i know where it belongs to in original image.
let me know if that makes sense.
thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle detection

Post by fmw42 »

You can try template matching. Get a subsection of your image or create a dark circle of the size you have in the image. Then use compare to compare the smaller template circle with the larger image. An example can be seen at viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076 That should produce a two-frame image of which the second is similar to what is shown, but in your case there should be 4 bright dots. The locations of those 4 dots, should be the corresponding location in the larger image where the upper left corner of the template best matches.

see
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/#compare
daffy

Re: circle detection

Post by daffy »

i have made this template and try to find circles from the image i get from compare command
but still circles are undetectable.
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle detection

Post by fmw42 »

try one dark centered circle for the template, similar in shading as in your image of multiple circles
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle detection

Post by fmw42 »

I tried several variations and the similarity image is not showing enough variation to pick out the best matches for your images. Sorry I tried negating the images and also making edge images and neither works well enough.
Post Reply