info = imfinfo('bwimage.png');
info.BitDepth
I = imread('bwimage.png');
BW = imbinarize(rgb2gray(I));
BWConv = bwconvhull(~BW);
BW = BW & BWConv;
figure()
h = imshow(BW);
axis on
stats = regionprops('table',BW,'Centroid','MajorAxisLength','Orientation'
nObjects = size(stats,1);
head(stats)
hold on
ph1 = plot(stats.Centroid(:,1), stats.Centroid(:,2), 'rs');
stats.Slope = atan(-stats.Orientation*pi/180);
stats.Intercep = stats.Centroid(:,2) - stats.Slope.*stats.Centroid(:,1);
stats.EndpointX = stats.Centroid(:,1) + [-1,1].* (stats.MajorAxisLength/1.6 .* sqrt(1./(1+stats.Slope.^2)));
stats.EndpointY = stats.Centroid(:,2) + [-1,1].* (stats.Slope .* stats.MajorAxisLength/1.6 .* sqrt(1./(1+stats.Slope.^2)));
mah = plot(stats.EndpointX.', stats.EndpointY.', 'r-')
Best Answer