How to find out the distance between the inner and outer edge of the image using the Matlab command [x,y]=ginput(1)?

Where ever you click on the following link image, matlab code must find out the two edges and find out the distance between the those two points using [x,y]=ginput(1). http://imageshack.us/photo/my-images/600/imfill.jpg

 Accepted Answer

I gave you code for calling ginput() in http://www.mathworks.com/matlabcentral/answers/57292#answer_69661 that calculates the distance between two points. Recall where it said:
% Calculate diameters:
outerDiameter = sqrt((xOuter-xCenter)^2+(yOuter-yCenter)^2)
innerDiameter = sqrt((xInner-xCenter)^2+(yInner-yCenter)^2)
Well that's just the Pythagorean theorem. You can replace the two x and y with any any two x and y to get the distance between two points.

2 Comments

But i don't know the center and how can i click mouse point at center in above link image?
I am not interested to find out the center by clicking it.
in this case can you find out the center by automatically?
Also not inttested to click the inner edge and outer edge by mouse pointer.
Just click on the circle (ONLY ONCE) at any point on it, code has take its center and find out the inner and outer dia without selectinig edges.
Whatever you suggested by clicking center,inner and outer edge so could we do the same thing by not selecting the points?
Looking up at the top (your original question here in this post right here), I believe I answered your question of how to find the distance between two points that you specified using ginput(), didn't I?
If you have a follow up to your prior question, where we showed you how to use regionprops(), then post your follow up question in that post, not this one.

Sign in to comment.

More Answers (2)

I would just use imdistline()

11 Comments

Yes, so would I. improfile() is also somewhat similar. Amongst numerous posts on this he seems to be bouncing back and forth between using automatic (i.e. regionprops) methods to find circle diameters and using manual methods by having the user manually specify points. I'm still puzzled why he can't just pick a method and go with it, and why there are lots of posts on this same ring/target/circle diameter issue.
improfile()!; I learn something new every day
I asked the question from the beginning to find out the center,ID and OD of the circle with manually(ginput) and without manually(regionprops).
Image Analyst answered me to that particular questions with manually, using ginput()and with out manually using rerionprops() mat lab commands.
Why i am asking these question i will explain
Let me consider the command regionprops().
It will gives me the cnetroid of the image nothing but half of the size of the image but in this same image,let us say my circle is moved at one of the four quadrant then how the image center becomes circle center?
I need circle center which is at one of the four quadrant or away from the image center.
Now let me consider the command ginput().
i asked the question that "How to find out the distance between the inner and outer edge of the circle image using the Matlab command [x,y]=ginput(1)?
Image Analyst replied to this question and he used the command ginput()
three times, in which first selection is at center of the circle but we don't know the center how can we locate? Second selection is at inner edge and third selection at outer edge of the circle but can we locate exact at edges?
In first case if i select the center as wrong (reason to select wrong:In the circle there is no hint to locate the center), automatically the inner and outer edge output becomes wrong.
So these are are the problems i faced that make me to ask these questions but my intention is not to puzzled you.
The following image link gives you the complete understanding: http://imageshack.us/photo/my-images/547/imagezdl.jpg/
The above image is at one of the corner,but to find out the center and ID and OD, if i use ginput() as three times i cant exactly locate center ,inner and outer edge using mouse pointer and also using reginprops() command,i am not getting the center of the circle but i am getting the center of the image((size(image))/2), also from this regionprops not getting the ID and OD.
The above link is my final image, if i do the math code operation over this image which image analysis ts suggested i am getting out put but not the accurate.
WITHOUT SELECTING THE CENTER ,INNER AND OUTER EDGE CAN WE FIND OUT THESE THREE PARAMETERS? THIS IS WHAT MY APPLICATION.
Now i hope you will completely under stand my question!!
If you threshold that image, leaving white as logical true (or 1), then regionprops() is going to return statistics for two objects, one for the solid white inner core of the circle, and the other for the remaining white background. The centroid property of the object with the eccentricity closest to 0 will be the centroid of the solid white inner core of the circle, no matter where it is in the image.
And if you invert the image either at the time of thresholding or immediately afterwards, so that the dark area becomes logical 1, then regionprops would, for the single-circle image, find only one object, and the centroid of that one object would be the centroid of the black ring. The regionprops MajorAxisLength would then be the outer diameter of the black ring. The calculation from more regionprops properties,
sqrt( 4 * (FilledArea - Area)/pi )
will then be the inner diameter of the black ring.
Good morning Sir,
I have gone through the above comment and I found TWO object statistics (for binary image) and ONE object statistics (for inverted binary image).
IN which i taken ONE object statistics, which i was got through matlab command for the image http://imageshack.us/photo/my-images/547/imagezdl.jpg/
For this same image manually i calculated the ID and OD using the command imtool(imagename),I got ID=194 and OD=248.
But here the problem is,
ID which i was calculated through manually is matching with math lab output [which you suggested sqrt(4 * (FilledArea - Area)/pi)]
but the OD MajorAxisLength (outer diameter of the black ring) is not matching,but practically it has to match, am i right? so what could be the problem?
COULD YOU CLARIFIE?
Area: 19363
Centroid: [144.1072 141.5697]
MajorAxisLength: 314.9522 (OD WHICH YOU SUGGESTED IN ABOVE COMMENT)
Eccentricity: 0.0698
FilledArea: 48540
sqrt( 4 * (48540 - 19363)/pi )=192.7416(ID WHICH YOU SUGGESTED IN ABOVE COMMENT)
The outer diameter is given by
sqrt( 4 * (FilledArea)/pi )
which is
sqrt( 4 * (48540)/pi )
ans =
248.6022
This is in agreement with what you found manually.
Odd. Why would MajorAxisLength be substantially different than the outer diameter in the case of a circle? Unless there are some stray pixels being picked up??
Thank you sir for your kind response? yes if any stray pixels picked up i think that could be the problem.
OD=*sqrt( 4 * (FilledArea)/pi )*
In that above command how to assign the FilledArea value from workspace, insted of writing sqrt(4*(48540)/pi )?
I tried and i am getting like Area:
Centroid:
MajorAxisLength:
Eccentricity:
FilledArea:
in command window but i don't have idea how to pick up filleddArea value, for assigned in above principle.
When you showed "Area: 19363" and so on, how did you generate that information? Show the code from the regionprops() call on to the place you display that information.
Here the code how i displayed the Area,FilledArea.....
imshow(I) (I=Inverted of binary image)
>> [L,num]=bwlabel(I);
>> regionprops(L,'Area','FilledArea')
ans = Area: 19363
FilledArea: 48540
>> sqrt(4*(Filledarea)/pi)
By using the above command i am getting the following error that is
??? Undefined function or variable 'Filledarea'.
How to eliminate above error?
(I mean how to write the code such that the above formula will take the FilledArea as 48540 and display the OD as 248 )
This is my question may be i didn't ask in proper way.
info = regionprops(L,'Area','FilledArea');
OD = sqrt(4*(info.FilledArea)/pi)

Sign in to comment.

threshold. Logically negate so the circle becomes the 1's. bwboundaries that. The result for that image would be a 2 x 1 cell array, each entry of which is an array of row and column coordinates that together form one of the boundaries. Find the minimum of the euclidean distances between all points in the first cell and all points in the second cell, and you will have found the minimum distances between the inner and outer boundaries.
You can toss in a ginput(1) if you really want; you would just ignore the value it returns.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!