draw circle on image

조회 수: 11 (최근 30일)
sangeeta
sangeeta 2013년 3월 18일
댓글: Image Analyst 2021년 6월 22일
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
sangeeta
sangeeta 2013년 3월 21일
ok, Thanks Spandan
Image Analyst
Image Analyst 2013년 3월 21일
편집: Image Analyst 2013년 3월 21일
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().

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 3월 18일
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
Image Analyst
Image Analyst 2021년 6월 22일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Muhammad Nauman Arshad
Muhammad Nauman Arshad 2020년 2월 19일
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;

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by