For those who do not have a newer Matlab version with bwconvhull included, I have written this short function designed to be an alternative to the usage
P= bwconvhull(BW,'objects');
and here it is:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function P = bwconvhull_alt(BW) | |
% usage: P is a binary image wherein the convex hull of objects are returned, BW is the input binary image | |
% P= bwconvhull_alt(BW); | |
warning off all | |
s=regionprops(logical(BW),'ConvexImage','BoundingBox'); | |
P=zeros(size(BW)); | |
for no=1:length(s) | |
P(s(no).BoundingBox(2):s(no).BoundingBox(2)+s(no).BoundingBox(4)-1,... | |
s(no).BoundingBox:s(no).BoundingBox(1)+s(no).BoundingBox(3)-1)=s(no).ConvexImage; | |
end | |
warning on all |
It uses the IP toolbox function regionprops, around for some time, to find the convex hull images of objects present, then inscribes them onto the output image using the bounding box coordinates. Simples!
No comments:
Post a Comment