Hi all, i have a two circles in an image which are concentric, i used a command [x,y]=ginput(1). Using the mouse pointer i click on the one of the concentric circles,with reference to the [x,y] point how to find out the inner dia,outer dia,center
Show older comments
Is it possible to draw a circle with reference to the {[x,y]=ginput(1)} single point.
3 Comments
Matt J
on 24 Dec 2012
Explain what that means.
Walter Roberson
on 24 Dec 2012
Should the largest circle be drawn from the starting point, that just touches one (or both) of the two concentric circles ?
Walter Roberson
on 26 Dec 2012
Accepted Answer
More Answers (3)
Image Analyst
on 25 Dec 2012
0 votes
See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F for code on how to draw circles and ellipses.
10 Comments
Naresh Naik
on 25 Dec 2012
Image Analyst
on 26 Dec 2012
I played around with the image a little bit and it was tricky because you have such bad illumination that the left part of the ring has some bright pixels in it. But when you try to fill areas, it will fill all those little glints in the ring PLUS the whole huge disc inside it. So it's difficult to get the area of just the ring. I could probably get it by doing an imclose on it, but first want to ask if all your images are going to be this crummy or are you able to improve your image capture setup. If you can't improve, then is this a homework assignment and you have to just do the best with what you are given? If you're stuck with bad images with side-to-side gradients in illumination, then you'd be best off trying to estimate that first and correct for it. That could be a project in itself since it looks like some of the image is totally saturated so you're going to have a lot of ad hoc conditions to check for. It's possible but a bit of work.
Naresh Naik
on 27 Dec 2012
Walter Roberson
on 27 Dec 2012
Image Analyst's formula of innerdiameters = sqrt(4 * (filledareas - areas) / pi); is correct to give the diameters. My version would have produced sqrt(-1)/2 times the proper result; use his version.
Naresh Naik
on 27 Dec 2012
Walter Roberson
on 27 Dec 2012
I had sqrt((areas - filledareas) / pi); which is wrong. filledareas is at least as large as areas, so that would have given sqrt() of a negative number, and would have been sqrt(-1) * sqrt((filledareas - areas) / pi) [notice the areas and filledareas changed place in the subtraction.]
My calculation was also of radius, the traditional Area = Pi*R^2 formula, but you want diameter instead of area, so you wanted a result twice as large as what I had calculated. The combined correction of the factor of 2 and the correction of the order is given by Image Analyst's formula, sqrt(4 * (filledareas - areas) / pi) which is the one you should use.
Naresh Naik
on 28 Dec 2012
Image Analyst
on 28 Dec 2012
Naresh Naik
on 31 Dec 2012
Image Analyst
on 31 Dec 2012
We've talked about that already. If you don't want to do it manually with ginput, then there are ways with thresholding and regionprops to find things automatically. You could also combine them if you want to find, say, just one pair of diameters rather than the whole set.
Walter Roberson
on 25 Dec 2012
0 votes
With regards to your current version of the question asking whether it is possible to draw a circle with reference to ginput(1) coordinates, the answer is YES, and the method is as linked to by Image Analyst in the FAQ.
Walter Roberson
on 25 Dec 2012
0 votes
The question you emailed me involved finding the inner and outer diameter of circles within a "bulls-eye" type pattern, and wanting to know how to find a diameter of a circle pointed to using ginput()
I would suggest that you just find all of the inner and outer diameters and then worry about the output.
To find the diameters, start by thresholding the image using "<" so that you get "true" for the dark areas. Then bwlabel() the binary image that results. regionprops() that, and request the Area and the FilledArea and the EquivDiameter. The EquivDiameter will give you the outer diameter. sqrt((Area - FilledArea) / pi) is the inner diameter and will be 0 for the innermost circle. Sort by EquivDiameter to get the order of the circles.
If you still want the user to be able to click to choose a particular point, then after the click, extract that same point from the labeled image, and the label will tell you the array index of regionprops results.
11 Comments
Naresh Naik
on 25 Dec 2012
Edited: Naresh Naik
on 25 Dec 2012
Image Analyst
on 25 Dec 2012
Edited: Image Analyst
on 25 Dec 2012
It does me no good if Naresh didn't post his image online. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers That's the best way since people generally don't like taking discussions off Answers and to email, since we're not providing a free private consulting service. Naresh if you needed to find the radii automatically via image analysis, you should have said so. If you're content with a manual method then just click at the center and click at the perimeter, using ginput(2) to capture both points in one call.
Walter Roberson
on 25 Dec 2012
Naresh, read the documentation for regionprops()
Naresh Naik
on 26 Dec 2012
Walter Roberson
on 26 Dec 2012
If you used
info = regionprops(YourBinaryImage, 'Area', 'FilledArea');
then
areas = [info.Area];
filledareas = [info.FilledArea];
innerdiameters = sqrt((areas - filledareas) / pi);
Image Analyst
on 26 Dec 2012
Edited: Image Analyst
on 26 Dec 2012
Or
innerdiameters = sqrt(4 * (filledareas - areas) / pi);
Note I reversed filledareas and areas so I won't get a negative number, and I added the 4.
Walter Roberson
on 26 Dec 2012
Edited: Walter Roberson
on 26 Dec 2012
Ah yes, you are correct, the formula I gave was for radius not diameter, and I do seem to have gotten the sign wrong.
Naresh Naik
on 28 Dec 2012
Image Analyst
on 28 Dec 2012
Image Analyst
on 29 Dec 2012
Like I said in another comment, see my code below where I use the manual method of ginput(1) like you asked for.
Walter Roberson
on 29 Dec 2012
As I wrote above "The EquivDiameter will give you the outer diameter"
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!