draw circle on image

8 views (last 30 days)
sangeeta
sangeeta on 18 Mar 2013
Commented: Image Analyst on 22 Jun 2021
I want to draw a circle with centre at centre of given image. Image get displayed but circle is missing. Without using hold on/off, a separate figure window shows circle, but i want the circle on the image. Plz correct the following code.
imshow(PICpng);
centx = x / 2;
centy = y / 2;
r = 10;
hold on;
theta = 0 : (2 * pi / 10000) : (2 * pi);
pline_x = r * cos(theta) + centx;
pline_y = r * sin(theta) + centy;
k = ishold;
plot(pline_x, pline_y, '*');
hold off;
  5 Comments
sangeeta
sangeeta on 21 Mar 2013
ok, Thanks Spandan
Image Analyst
Image Analyst on 21 Mar 2013
Edited: Image Analyst on 21 Mar 2013
Spandan, does the help's "See also" connect to other toolboxes? If so, then the help for rectangle(), which people usually use to draw circles, should mention viscircle().

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 18 Mar 2013
It was working. Your x and y were probably messed up. Try this:
PICpng = imread('peppers.png');
[rows columns numberOfColorChannels] = size(PICpng)
x = columns/2
y = rows/2
imshow(PICpng);
centx = x / 2;
centy = y / 2;
r = 60;
hold on;
theta = 0 : (2 * pi / 10000) : (2 * pi);
pline_x = r * cos(theta) + centx;
pline_y = r * sin(theta) + centy;
k = ishold;
plot(pline_x, pline_y, 'r-', 'LineWidth', 3);
hold off;
  10 Comments
Image Analyst
Image Analyst on 22 Jun 2021
Once you have a mask for the inside the red circle (call poly2mask() if you need to), you can do
pixelsInside = binaryImage(circleMask);
if all(pixelsInside)
% All values in mask are true/white/1
else
% At least one pixel is false/black/0.
end

Sign in to comment.

More Answers (1)

Muhammad Nauman Arshad
Muhammad Nauman Arshad on 19 Feb 2020
ICpng = imread('peppers.png');
[rows columns numberOfColorChannels] = size(PICpng)
x = columns/2
y = rows/2
imshow(PICpng);
centx = x / 2;
centy = y / 2;
r = 60;
hold on;
theta = 0 : (2 * pi / 10000) : (2 * pi);
pline_x = r * cos(theta) + centx;
pline_y = r * sin(theta) + centy;
k = ishold;
plot(pline_x, pline_y, 'r-', 'LineWidth', 3);
hold off;

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!