GUI: how to make the user able to add or delete circles in an image.

5 views (last 30 days)
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.

Answers (2)

Prashant Birajdar
Prashant Birajdar on 10 Oct 2015
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 Comment
Jonas Fisker
Jonas Fisker on 10 Oct 2015
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.

Sign in to comment.


Prashant Birajdar
Prashant Birajdar on 10 Oct 2015
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!