GUI: how to make the user able to add or delete circles in an image.
4 次查看(过去 30 天)
显示 更早的评论
Hi I'm trying to program a GUI that can detect circular objects in an image, and make the user able to add or delete circles manually. I'm using the circle finder program to detect circles in the image and that part works, but i'm having difficulty writing the part that makes the user able to add or delete circles manually. Your help will be much appreciated.
0 个评论
回答(2 个)
Prashant Birajdar
2015-10-10
Dear,Jonas Fisker,
To add circle on image you need to hold the current plot. try the following code, it may work.
Image = imread('peppers.png'); % Read the image fig = figure('menubar','none','Position',[250 150 840 440]); % Create Figure panel = uipanel('Parent',fig); % Create panel in figure
imaxes = axes('Parent',panel,'Units',... 'Pixels'); % Create axis on panel to show image and your plot imshow(Image);
[u v] = ginput(1); % Get input from user
hold ('on');
h1 = plot(u,v,'w+',u,v,'wo','markersize',10);
[u(2) v(2)] = ginput(1); %Get input from user
h1(3:4) = plot(u,v,'r+',u,v,'bo','markersize',10);
delete (h1);
A = diff(u);
B = diff(v);
R = hypot(A,B);
P = [u(1)-R v(1)-R 2*R 2*R];
h1 = imellipse(imaxes,P);
position = wait(h1); % Wait for double click
% store position for later plotting
X = position(:,1);
Y = position(:,2);
delete(h1);
h1 = plot(X,Y,'-r',X,Y,'--k');
hold ('off');
Prashant Birajdar
2015-10-10
Dear,Jonas Fisker,
To add circle on image you need to hold the current plot. try the following code, it may work.
Image = imread('peppers.png'); % Read the image
fig = figure('menubar','none','Position',[250 150 840 440]); % Create Figure
panel = uipanel('Parent',fig); % Create panel in figure
imaxes = axes('Parent',panel,'Units',... 'Pixels'); % Create axis on panel to show image and your plot imshow(Image);
[u v] = ginput(1); % Get input from user
hold ('on');
h1 = plot(u,v,'w+',u,v,'wo','markersize',10);
[u(2) v(2)] = ginput(1); %Get input from user
h1(3:4) = plot(u,v,'r+',u,v,'bo','markersize',10);
delete (h1);
A = diff(u);
B = diff(v);
R = hypot(A,B);
P = [u(1)-R v(1)-R 2*R 2*R];
h1 = imellipse(imaxes,P);
position = wait(h1); % Wait for double click
% store position for later plotting
X = position(:,1);
Y = position(:,2);
delete(h1);
h1 = plot(X,Y,'-r',X,Y,'--k');
hold ('off');
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!