centerobject(bw)

a small function that centers an object with its centroid to the center of the image
752 Downloads
Updated 19 Aug 2015

View License

For a lot of shape descriptors (e.g. Fourier descriptors, Zernike Moments etc.) in image feature generation it is necessary to have the objected centered to the image center. Meaning that the center of mass of the object lies in the middle of the image.
Because i couldn't find any similar function to center objects in images i wrote this little function for myself. With this submission i hope i can save some of your working time to figure out a similar script.
The function does extend the image in case that the translation needed to put the object to the image center does not fit withhin the image boundarys.
CM = CENTERMASK(BW) needs and MxN logical image as input with only one object present and returns and RxR logical image with the object centered to the middle of the image.
Due to numerical reasons there can be a shift of maximum +- 0.5.
The function is tested with the MPEG-7 Dataset and worked for all images perfectly. The above image is one of the results.
Look at the centerobject_example file to see how the function works and what it needs as input etc.
If you have any suggestions or questions, feel free to write a comment.
(I wrote this function with Matlab 8.1 (R2013a) but i am pretty sure it will work with older releases)

Cite As

Frederik Kratzert (2024). centerobject(bw) (https://www.mathworks.com/matlabcentral/fileexchange/52560-centerobject-bw), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Zernike Polynomials in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0