Draw Circle on picture and then save the drawn circle on the picture

15 views (last 30 days)
Hi there,
I am trying to open a picture in matlab, then draw a circle on it using p = drawcircle('LineWidth',3,'Color','black');
up until here everything works well. I do not manage to export the drawn circle together with the picture as a new file.
Any help is much appreciated!
Here 'all' the code for now:
image=imread('IMG_6309.jpeg');
imshow(img)
p = drawcircle('LineWidth',3,'Color','black');

Answers (1)

KSSV
KSSV on 3 May 2021
Image = imread('peppers.png');
imshow(Image)
% plot circle
hold on
th = 0:pi/50:2*pi;
R = 50 ;
C = round([size(Image,2)/2 size(Image,1)/2]) ;
xunit = R * cos(th) + C(1);
yunit = R * sin(th) + C(2);
plot(xunit, yunit, 'r');
% plot the circle center
scatter(C(1), C(2), 20, 'r+');
hold off
F = getframe ;
% save the image:
imwrite(F.cdata,'test.png')
  4 Comments
Elmar Kert
Elmar Kert on 3 May 2021
ah go it, it's working now thank you! Do you also happen to know how to count the numbers of pixels inside the circle? :)
KSSV
KSSV on 3 May 2021
clc; clear all ;
Image = imread('peppers.png');
imshow(Image)
% plot circle
hold on
th = 0:pi/50:2*pi;
R = 50 ;
C = round([size(Image,2)/2 size(Image,1)/2]) ;
xunit = R * cos(th) + C(1);
yunit = R * sin(th) + C(2);
plot(xunit, yunit, 'r');
% count pixels inside the circle
x = 1:size(Image,2) ;
y = 1:size(Image,1) ;
[X,Y] = meshgrid(x,y) ;
idx = inpolygon(X,Y,xunit,yunit) ;
nnz(idx)

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!