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

0 votos

Use the rectangle() function?

5 comentarios

Mihael  Rakic
Mihael Rakic el 27 de Dic. de 2017
Editada: Mihael Rakic el 27 de Dic. de 2017
Hi, I have tried this and changed Circle for Rectangle, but I got the following error:
The POSITION matrix must have four columns for shape Rectangle
Image Analyst
Image Analyst el 27 de Dic. de 2017
Did you follow the direction in the help for rectangle where it creates a circle? What did you pass in for Position and Curvature? You forgot to include your line of code. I can't know unless you tell me.
Mihael  Rakic
Mihael Rakic el 27 de Dic. de 2017
Editada: Mihael Rakic el 27 de Dic. de 2017
Sorry this is my code:
if true
coder.extrinsic('imfindrectangle');
[centers,radii] = imfindrectangle(lijn,[10, 15], 'ObjectPolarity','dark', 'Sensitivity',0.6,'Method','twostage');
corner1=centers radii-0.5;corner2=centers radii+0.5;corner3=centers radii+0.5;corner4=corner2;
rectangle('Position',[corner1 corner2 corner3 corner4])
lijn = insertShape(lijn,'rectangle',[centers radii],'LineWidth',2);
end
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

0 votos

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 Image Processing and Computer Vision en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Dic. de 2017

Respondida:

el 28 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by