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?

 採用された回答

Image Analyst
Image Analyst 2017 年 12 月 27 日

0 投票

Use the rectangle() function?

5 件のコメント

Mihael  Rakic
Mihael Rakic 2017 年 12 月 27 日
編集済み: Mihael Rakic 2017 年 12 月 27 日
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 2017 年 12 月 27 日
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 2017 年 12 月 27 日
編集済み: Mihael Rakic 2017 年 12 月 27 日
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 2017 年 12 月 27 日
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 2017 年 12 月 28 日
編集済み: Mihael Rakic 2017 年 12 月 28 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Mihael  Rakic
Mihael Rakic 2017 年 12 月 28 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeImage Processing and Computer Vision についてさらに検索

質問済み:

2017 年 12 月 27 日

回答済み:

2017 年 12 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by