MATLAB Answers

how to calculate the center of an object in binary image

61 views (last 30 days)
hellow dears i need support to calculate the center of an object in binary image, the binary image has only one object so that i need to find the center of that object in order to crop the object from the binary image as in attached image

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 27 Feb 2016
You do not need the center of the blob to crop it from the image. You need the bounding box.
measurements = regionprops(binaryImage, 'BoundingBox');
croppedImage = imcrop(binaryImage, measurements.BoundingBox);

  8 Comments

Show 5 older comments
Image Analyst
Image Analyst on 28 Feb 2016
You forgot to give the rest of the error message. Anyway, here's a full demo for you, attached.
haider alnaqeeb
haider alnaqeeb on 28 Feb 2016
Dear Image Analyst: first thing i am very grateful for your kind and fast support i really appreciate your kindness and i test your code it is excellent and give me the right result, if you don't mind can you give me your email in case i need your kind support. Kind Regards
Image Analyst
Image Analyst on 28 Feb 2016
You're welcome. Thanks for accepting. You don't need my email because if you need help again you can post back here in Answers and possibly get more answers than from just me.

Sign in to comment.

More Answers (2)


Walter Roberson
Walter Roberson on 27 Feb 2016
Use regionprops() and ask for Centroid

  7 Comments

Show 4 older comments
haider alnaqeeb
haider alnaqeeb on 27 Feb 2016
Mr. Walter Roberson i really grateful for your kind support but i test your code of finding the center and it give me the center of full size of binary image not the center of the object in it? so Mr. Walter Roberson can you give me the code of finding the center of an object assuming that the binary image has only one object as the attached image?? Kind Regards
haider alnaqeeb
haider alnaqeeb on 27 Feb 2016
can we make the object in the binary image as an array which it is pixels has value of 1 and we find the center of this array which is the center of the object?? i mean we find the center of array of pixels which has value 1 ??
Walter Roberson
Walter Roberson on 27 Feb 2016
regionprops should already act that way.
Note: the page you posted, aaaaa.png, has two or more blobs, because it has the grayscale image at the left and the diagram at the right. You need to be operating on just the grayscale image.

Sign in to comment.

Sign in to answer this question.