How to insert multiple circles on selected points on an image?

9 views (last 30 days)
Hello, I am trying to find the (x,y) coordinates of 14 points on an image and draw circles and label them with numbers.
I have the following code. I am able to find the coordinates, however, it's only showing one circle on the last point I select. Can someone please help me and figure out what I am doing wrong? Also, how do I insert numbers along with the circles?
Thanks in advance!
%%
moving=imread('biopsy burn 2.JPG');
imagesc(moving);
[x,y]=getpts;
pos=[x,y];
for i = 1:length(pos)
shape=insertShape(moving,'circle',[pos(i,:),40],'LineWidth',10,'Color', 'White');
end
figure
imagesc(shape)

Answers (1)

DGM
DGM on 9 Jul 2021
I don't have CVT, so I can't test this, but you're never saving the output of shape. Each time, you're starting from the source image.
You shouldn't need to use the loop anyway. InsertShape() accepts a point list directly
% should be able to pass a list of all points and radii in one call without the loop
shape=insertShape(moving,'circle',[pos,40*ones(size(pos,1),1)],'LineWidth',10,'Color', 'White');
See the section on the 'position' property:
As far as text labels go, you should be able to use insertText(), which can similarly take multiple points at once.
  2 Comments
Anisha Jamil
Anisha Jamil on 9 Jul 2021
Thank you so much! I was wondering if you would be able to help me with this part too!!
https://www.mathworks.com/matlabcentral/answers/875148-how-to-specify-different-colors-to-multiple-shape-inserts-on-an-image?s_tid=srchtitle
Anisha Jamil
Anisha Jamil on 9 Jul 2021
The link is where I posted an another question related to this

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!