MATLAB Answers

how can get coordinate of left and top and bottom and right object of binary Image?

15 views (last 30 days)
jack nn
jack nn on 27 May 2015
Commented: jack nn on 28 May 2015
hi everyone I have an Image that is binary...I want to imcrop a segment of image that contain all of objects. but I want to do this in a way that the rect that I choose be smallest. I think if I have the coordinates of the objects that is in( left and top) of Img and (bottom and right) I can do this. Can you help me? Is there any way?
I mean object that I use a red circle around them in this image.


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 27 May 2015
stats = regionprops(YourImage, 'BoundingBox');
boxes = vertcat(stats.BoundingBox);
lefts = boxes(:,1);
rights = lefts + boxes(:,3);
tops = boxes(:,2);
bottoms = tops + boxes(:,4);
upperleft = [min(lefts), min(tops)];
lowerright = [max(rights), max(bottoms)];
cropat = [upperleft, (lowerright - upperleft)];


jack nn
jack nn on 27 May 2015
thanks dear Walter Roberson I want to result be an image like this:
but when I use this code my result is like this:
Can you help me?
Image Analyst
Image Analyst on 27 May 2015
It's just indexing to extract it!
croppedImage = binaryImage(upperLeft(2):lowerRight(2), upperLeft(1):lowerRight(1));
jack nn
jack nn on 28 May 2015
thanks @Image Analyst and @Walter Roberson. excuse me I am beginner. I really appreciate you for your help.

Sign in to comment.

More Answers (0)

Sign in to answer this question.