![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
How to create a flexible rectangular box with a height and widht line at the center so that I can measure the height and width of the particular object in the image
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ankit Gupta
le 6 Juin 2014
Commenté : Image Analyst
le 10 Juin 2014
Hi All,
I have an image , right now I am using imline to calculate the height and width of the object in an image, I am wondering if have some tool in which we can create box around the object the perpendicular height and width line to measure. is there any tool or a way to create in matlab
0 commentaires
Réponse acceptée
Image Analyst
le 8 Juin 2014
Modifié(e) : Image Analyst
le 8 Juin 2014
You can use regionprops() to get the bounding box (length and width parallel to the image edges), convex hull, and major and minor axis lengths (fitting the blob(s) to an ellipse). See my Image Segmentation tutorial for a demo: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862.
If you want the farthest two points in an image and the cross sectional width at the mod point, then let me know, because that's not built in.
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
3 commentaires
Image Analyst
le 10 Juin 2014
Anikit: Please run my attached spatial calibration demo.
Plus de réponses (3)
Matt J
le 10 Juin 2014
Modifié(e) : Matt J
le 10 Juin 2014
I think the easiest compromise is to use impoly to draw an approximate rectangle around the tooth,
h=impoly(gca,'Closed',1);
Then, you can replace the polygon with its bounding rectangle using rectify(h) below. It relies on minboundrect from the File Exchange. You can tweak the vertices of the polygon interactively and re-apply rectify(h) until you are satisfied with the positioning.
function rectify(h)
pos=getPosition(h);
[rectx,recty] = minboundrect(pos(:,1),pos(:,2));
newpos=[rectx,recty];
setPosition(h,newpos(1:end-1,:));
end
Matt J
le 6 Juin 2014
Just as there is imline, there is also imrect.
3 commentaires
Matt J
le 6 Juin 2014
But can I rotate the rectangle along the axis?
No, you cannot rotate an imrect.
also I want the Cross " +" inside the rectangle . Is it possible to do that?
I don't know what "the Cross" refers to.
Matt J
le 8 Juin 2014
Another approach to consider is to use regionprops to compute the area and perimeter of the object. From the area and perimeter, you can solve for width and height.
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!