Page 1 of 1

Find Circle Parameter

Posted: 2013-07-17T04:27:01-07:00
by gowribala
Hai...

I have a image with two circles.i need to find the center and radius of these two circles.

I tried hough transform but it wont produces exact output.

please guide me how to find center and radius of these two circles in my image.

Re: Find Circle Parameter

Posted: 2013-07-17T09:27:14-07:00
by fmw42
IM does not have Hough Transforms. If the two circles do not overlap and are on a constant background, you can crop them and trim the image to squares. The width or height of the square image will be the diameter. Take half of that and it will be the radius and center.

The only other way I know is by trial and error by guessing the radius and center and drawing a circle with -draw on your image and see how it aligns. Repeat with corrections until it matches. See http://www.imagemagick.org/Usage/draw/#circles

Re: Find Circle Parameter

Posted: 2013-07-17T11:44:54-07:00
by snibgo
gowribala: Can you post a sample image? Put it somewhere like dropbox and post the URL here.

Re: Find Circle Parameter

Posted: 2013-07-17T23:51:34-07:00
by gowribala
Thanks for your reply...

But i need find the parameter of circles by program (c or c++)not manually.my project is purely based on image processing.

I need to find whether input image having circles or not ,if this having circles means have to find circles parameter.

Input image having two concentric circles (black color) on white background with some noise.

I have attached the image for your reference.

Image

Re: Find Circle Parameter

Posted: 2013-07-18T06:04:56-07:00
by snibgo
The image contains no circles at all.

It does contain a number of marks that are reasonably close to being circles. You need to decide what determines "nearly a circle".

A possible approach would be to choose a possible centre and radius, draw a circle, and count how many corresponding pixels are black. If this is above a certain proportion, record this as "nearly a circle". Repeat for all possible centres and radii.

Re: Find Circle Parameter

Posted: 2013-07-18T10:09:58-07:00
by fmw42
If you can locate the exact center of a circle in the image, you an do a -distort depolar to convert from cartesian to polar coordinates. The result will show a (nearly) horizontal line for the circle. Then a Straight Line Hough Transform should be able to find it. Note IM does not have Hough Transforms.

I would have thought that your hough transform for circle would have worked. Did you try thickening the lines with morphologic operators or perhaps invert the black <-> white using -negate.

see http://www.imagemagick.org/Usage/morphology/

Re: Find Circle Parameter

Posted: 2013-07-19T05:11:11-07:00
by gowribala
Thanks for your reply...

I already used hough transform and another method which you mentioned above(assume set of centers and radius and draw) ,but it produced poor output.

My Region Of Interest(outer circle - inner circle) is located between these two circles.I want to separate that particular area alone,so only i need to calculate radius and center of these two circles.

please guide me how can i segment these image and get my Region Of Interest....

Re: Find Circle Parameter

Posted: 2013-07-19T09:27:13-07:00
by snibgo
My suggestion is brute-force. It needs three nested loops: radius, x and y.

fmw42's suggestion is more intelligent, needing just two nested loops: x and y, but the processing is probably more complex. It could (if desired) find ellipses more easily than my suggestion.

Here's an example of my suggestion, for just one radius (35). I make circ.png with a white circle on a transparent background. Within the loop, I crop the source image to the same size and copy the red channel from circ.png. Where the circ.png circle intersects a black pixel from the source, the pixel becomes red. So I count the number of red pixels.

Windows script:

Code: Select all

setlocal enabledelayedexpansion

set SRC=2circles.jpg

set RAD=35

%IM%convert -size 71x71 xc:None ^
  -stroke White -fill None ^
  +antialias ^
  -draw "translate 35,35 circle 0,0 0,35" ^
  circ.png

del circFnd.txt

for /L %%x in (0,1,58) do (
for /L %%y in (0,1,58) do (
echo %%x, %%y, : >>circFnd.txt
%IM%convert %SRC% ^
  -crop 71x71+%%x+%%y +repage ^
  circ.png ^
  -compose CopyRed -composite ^
  txt:- | find /C "red" >>circFnd.txt
)
)

chBin /icircFnd.txt /f": \r\n" /ocf.csv
cSort /icf.csv /ocf2.csv /k2 /r
The best result is 64 red pixels, at location 53,43. Here it is:

Code: Select all

convert 2circles.jpg -crop 71x71+53+43 +repage circ.png -compose CopyRed -composite circ35fnd.png
Image

Re: Find Circle Parameter

Posted: 2013-07-19T09:36:53-07:00
by snibgo
Or, very much easier and faster:

Code: Select all

D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\convert -size 71x71 xc:White -stroke Black -fill None +antialias -draw "translate 35,35 circle 0,0 0,35" circB.png

D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\compare -metric RMSE -subimage-search 2 circles.jpg circB.png NULL:
8902.08 (0.135837) @ 53,43