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

조회 수: 3 (최근 30일)
Is it possible to draw a circle with reference to the {[x,y]=ginput(1)} single point.
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 12월 24일
Should the largest circle be drawn from the starting point, that just touches one (or both) of the two concentric circles ?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 12월 28일
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
FSh
FSh 2021년 4월 11일
Is it possible to convert the x,y values obtained with ginput to pixcel values without using impixelinfo ?!
Image Analyst
Image Analyst 2021년 4월 11일
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, :)

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Image Analyst
Image Analyst 2012년 12월 25일
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
Naresh Naik
Naresh Naik 2012년 12월 31일
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?
Image Analyst
Image Analyst 2012년 12월 31일
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
Walter Roberson 2012년 12월 25일
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
Walter Roberson 2012년 12월 25일
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
Image Analyst
Image Analyst 2012년 12월 29일
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
Walter Roberson 2012년 12월 29일
As I wrote above "The EquivDiameter will give you the outer diameter"

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by