MATLAB: Calulate width of every boundary point to majorAxisLength

boundariesdistanceMATLABregionpropswidth binary image

I have a binary image and I need to remove the part that represents the head of an animal. I know that the point of width derivate has a sharp peak shows the head begin. So I use regionprops properties and bwboundaries to identify the centroid, majorAxisLength and draw the edge in object, but I can't identify how I can find the width of every point to see the derivate and remove this part. Anyone can help me with this task?
This is one of the images with the majorAxis drawned and edges of a pig body.

Best Answer

Just count pixels in vertical direction with sum()
I = imread('image.png');
I1 = im2bw(I); % binary image
h = sum(I1); % height in pixels (just summation rows of a matrix)
dh = diff(h); % derivative of height in pixels