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

 Accepted Answer

Here's how to do it with ginput(1), rather than automatically, just like you asked for:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
imshow('C:\Users\Naresh\Documents\Temporary\intq.png');
% Ask for center using ginput(1)
message = sprintf('Please click at the center of the circles');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
[xCenter, yCenter] = ginput(1)
hold on;
markerSize = 30; % Size of the cross.
lineWidth = 2; % Thickness of the cross.
plot(xCenter, yCenter, 'r+', 'MarkerSIze', markerSize, 'LineWidth', lineWidth);
% Ask for inner edge using ginput(1)
message = sprintf('Please click at the inner edge of the circles');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
[xInner, yInner] = ginput(1)
% Draw a cross at the point where they clicked.
plot(xInner, yInner, 'r+', 'MarkerSIze', markerSize, 'LineWidth', lineWidth);
% Draw a line to it.
line([xCenter, xInner], [yCenter, yInner], 'Color', 'b', 'LineWidth', lineWidth);
% Calculate diameter:
innerDiameter = sqrt((xInner-xCenter)^2+(yInner-yCenter)^2)
% Ask for outer edge using ginput(1)
message = sprintf('The inner diameter = %.2f\n\nPlease click at the outer edge of the outer circles', innerDiameter);
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
[xOuter, yOuter] = ginput(1)
plot(xOuter, yOuter, 'r+', 'MarkerSIze', markerSize, 'LineWidth', lineWidth);
% Draw a line to it.
line([xCenter, xOuter], [yCenter, yOuter], 'Color', 'b', 'LineWidth', lineWidth);
% Calculate diameters:
outerDiameter = sqrt((xOuter-xCenter)^2+(yOuter-yCenter)^2)
innerDiameter = sqrt((xInner-xCenter)^2+(yInner-yCenter)^2)
message = sprintf('The outer diameter = %.2f\nThe inner diameter = %.2f',...
outerDiameter, innerDiameter);
uiwait(helpdlg(message));

2 Comments

Is it possible to convert the x,y values obtained with ginput to pixcel values without using impixelinfo ?!
Yes
[xInner, yInner] = ginput(1);
row = round(yInner); % Make sure it's an integer, not a fractional value.
column = round(xInner);
pixelValue = yourImage(row, column, :)

Sign in to comment.

More Answers (3)

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

I gone throuth http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F. and i found that to create a 2D logical image of a solid circle (a disc), we must know the radius. But in my application i don't know the radius so how can i draw the logical circle. (My image size was 960x1280)
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.
Thanks for your suggestion and i came to know that there is no proper illumination on image which i was captured earlier. If i captured with full of illumination can i go through the following step, which are your earlier suggestions that is
info = regionprops(BinaryImage, 'Area', 'FilledArea'); then areas = [info.Area]; filledareas = [info.FilledArea]; innerdiameters = sqrt((areas - filledareas) / pi);
Or innerdiameters = sqrt(4 * (filledareas - areas) / pi);
and in your last answer you mentioned that you gave the formulas for radius not for diameter so how to proceed further?
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.
Thank you Sir, but i am not getting exactly what is mean by your version produced 0 + 0.5000i (sqrt(-1)/2) times the proper result? and here what do you mean by his version ? if you don't mind could you tell.
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.
Hello Walter Roberson,
I gone through the formula innerdiameters = sqrt(4 * (filledareas - areas) / pi).
Actually the area is nothing but a Scalar,the actual number of pixels in the region.
my question is here the region represent whether black portion of one of the four circles or white portion?
The inner diameter we are getting from the formula that belongs to which circle?
how to get outer dia of the same circle?
But my final gole is to find out the ID and OD of any one of these four(BLACK) circles using [x,y]=ginput(1). How to proceed?
Good Morning Sir, The above matlab code giving the output by manually we are selecting center ,inner and outer diameter from these information we are finding the ID,OD and it's Center.
But without selecting center ,ID and it's OD can we do the same job?
i mean you can select any one of the circle from that we can get (x,y) co-ordinate and intensity value of that image can we find out the center ,ID and OD. Note: Do not use [x,y]=ginput(1) more than once in a programme. Is this possible to solve through matlab code?
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.

Sign in to comment.

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.
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

BW = imread('int.bmp'); BW = imread('int.bmp'); level=graythresh(BW); l=bwlabel(BW); r=regionprops(BW) area(r)
but i am getting the following error (and how to request for area,filled area and equivdiameter)
??? Undefined function or method 'real' for input arguments of type 'struct'. Error in ==> xychk at 42 x = real(y); y = imag(y); Error in ==> area at 47 [msg,x,y] = xychk(args{1:nargs},'plot');
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.
Hello Walter Roberson i gone through the regionprops and i found that area(binaryimage) gave me the image and also came to know that filledArea is in nothing but the salar specifying the number of on pixels in FilledImage.
you told me that sqrt((Area - FilledArea) / pi) which gives the inner diameter. how to get the Area and FilledArea in the form of matrix to subtract from area to filledarea.
If you used
info = regionprops(YourBinaryImage, 'Area', 'FilledArea');
then
areas = [info.Area];
filledareas = [info.FilledArea];
innerdiameters = sqrt((areas - filledareas) / pi);
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.
Ah yes, you are correct, the formula I gave was for radius not diameter, and I do seem to have gotten the sign wrong.
Hello Walter Roberson good evening,
innerdiameters = sqrt((areas - filledareas) / pi); the above formula which you suggested perfectly working, but that is giving me the outer diameter of the each circles not the inner diameter of a bull eye image you can found this image in following link which is perfectly illuminated.
The result which i got through the above formula i corrected with the matlab imtool(binaryimage); i measured the diameter of the each circles manually with matlab tool in pixels these values are equal to the output value. so how to find out the inner diametre of the first 3 circles in pixels?
You saw his answer: above - you even responded to it so I'm not sure why you are asking again.
Like I said in another comment, see my code below where I use the manual method of ginput(1) like you asked for.
As I wrote above "The EquivDiameter will give you the outer diameter"

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!