make a box around a circle

2 visualizaciones (últimos 30 días)
Mihael  Rakic
Mihael Rakic el 27 de Dic. de 2017
Respondida: Mihael Rakic el 28 de Dic. de 2017
Hi, I have a code that detects a circle in the picture, but what I wan't is to make a rectangle that surrounds the circle. The code that I use is:
if true
function output_image = findCircels(Gevoeligheid,lijn,StraalMin,StraalMax)
output_image = lijn;
coder.extrinsic('imfindcircles');
[centers,radii] = imfindcircles(lijn,[StraalMin, StraalMax], 'ObjectPolarity','dark', 'Sensitivity',Gevoeligheid,'Method','twostage');
lijn = insertShape(lijn,'Circle',[centers radii],'LineWidth',5);
output_image=lijn;
end
Does anyone know how I can make this box around the circle and retract the coordinates of the edges of the rectangle?

Respuesta aceptada

Image Analyst
Image Analyst el 27 de Dic. de 2017
Use the rectangle() function?
  5 comentarios
Image Analyst
Image Analyst el 27 de Dic. de 2017
So I guess the answer is "No, I did not look at the documentation for rectangle to see how they created a circle, and I did not pass anything in for curvature." So . . . why not? Here is the link to the documentation:
and here is the example:
pos = [2 4 2 2];
rectangle('Position',pos,'Curvature',[1 1])
axis equal
Also note that the Position variable is [xLeft, yTop, xWidth, yHeight], not the coordinates of the 4 corners or whatever you had.
You might need to call hold on to prevent the rectangle from blowing away any image or data already in your axes.
Also, state whether you want the circle burned into an image or if you just want it to be put into the overlay (like the rectangle function does).
Mihael  Rakic
Mihael Rakic el 28 de Dic. de 2017
Editada: Mihael Rakic el 28 de Dic. de 2017
Thank you. I saw the examples and have a question about that. There is an example that shows how you can place a rectangle around a circle, but in this example the position of this circle is fixed. In my case there is a picture and a code searches the circle. The location of this circle is variable and then I need to place a rectangle around this circle.

Iniciar sesión para comentar.

Más respuestas (1)

Mihael  Rakic
Mihael Rakic el 28 de Dic. de 2017
I found the solution. With the imfindcircles i got the coordinates of the circle and the radii. Then I retracted the radii from the coordinates of the circle for the lower left corner of the rectangle and used these coordinates in the insertShape function

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by