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 comentarios

Jan
Jan el 18 de Mzo. de 2013
Editada: Jan el 18 de Mzo. de 2013
I have formatted youz code. Please read the instructions and use the "{} Code" button, Thanks.
What are x and y? How large is your image?
sangeeta
sangeeta el 19 de Mzo. de 2013
Editada: sangeeta el 19 de Mzo. de 2013
Thankyou Jan for the correction.
x and y are length and width of image (500, 400) Image can be of varying sizes, the one I m using is of 5ookb.
Spandan Tiwari
Spandan Tiwari el 20 de Mzo. de 2013
Editada: Spandan Tiwari el 20 de Mzo. de 2013
FYI, there's a function in the Image Processing Toolbox called VISCIRCLES which can be used for drawing circles. The basic syntax takes the centers and radii of the circles and draws them.
sangeeta
sangeeta el 21 de Mzo. de 2013
ok, Thanks Spandan
Image Analyst
Image Analyst el 21 de Mzo. de 2013
Editada: Image Analyst el 21 de Mzo. de 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().

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 18 de Mzo. de 2013

0 votos

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 comentarios

sangeeta
sangeeta el 19 de Mzo. de 2013
its still the same. Kindly find out the loophole.
Jan
Jan el 19 de Mzo. de 2013
Pleas explain, what is still the same. I do not get, what you are exactly asking for.
Image Analyst
Image Analyst el 19 de Mzo. de 2013
It's DEFINITELY not the same. My code works. Your code doesn't. Did you copy and paste my code? Evidently not. So let's see your new code. Did you actually make any changes to it? Like specifying values for x and y?
sangeeta
sangeeta el 20 de Mzo. de 2013
Thanks alot. Its working. Removed comments, placed image in current directory, removed some other irrelevant code...
Image Analyst
Image Analyst el 20 de Mzo. de 2013
So you did change/break my code. You mixed up x and y with rows and columns. x=columns, and y = rows. You have it the opposite way. Try
[y, x]=size(pngPIC);
sangeeta
sangeeta el 20 de Mzo. de 2013
Yes, I mixed up x and y. Thankyou.
rubina naz
rubina naz el 22 de Oct. de 2018
thanks alot it is working...
RAKESH KUCHANA
RAKESH KUCHANA el 21 de Jun. de 2021
Hello Image Analyst, I saw the code of drawing circle on image and it worked out. Can you explain how to identify whether the red circled area contains all white pixel area or not? Please provide code for it.
The sample images are provided for your reference.
Image Analyst
Image Analyst el 22 de Jun. de 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

Iniciar sesión para comentar.

Más respuestas (1)

Muhammad Nauman Arshad
Muhammad Nauman Arshad el 19 de Feb. de 2020

0 votos

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;

Categorías

Más información sobre Particle & Nuclear Physics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Mzo. de 2013

Comentada:

el 22 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by