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.

回答(2 个)

Prashant Birajdar
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');
  1 个评论
Jonas Fisker
Jonas Fisker 2015-10-10
Dear Prashant Birajdar
Thanks for the reply, it works great :) Do you know a way to select, move and delete circles, circles previously found by the circle finder program.

请先登录,再进行评论。


Prashant Birajdar
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');

Community Treasure Hunt

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

Start Hunting!

Translated by