How can i find the Majoraxislength and Minoraxislength of each cell present in binary image ?

4 次查看(过去 30 天)

采纳的回答

Jonas
Jonas 2022-11-29
编辑:Jonas 2022-11-29
a call to regionprops should suffice:
clear;
im=imread("image.png");
im=rgb2gray(im); % to grayscale
im=im~=0; % make binary image
imshow(im)
stats = regionprops('table',im,'Centroid','MajorAxisLength','MinorAxisLength');
% check if the results make sence
centers = stats.Centroid;
diametersMax = max([stats.MajorAxisLength stats.MinorAxisLength],[],2);
diametersMin = min([stats.MajorAxisLength stats.MinorAxisLength],[],2);
radiiMax = diametersMax/2;
radiiMin = diametersMin/2;
hold on
viscircles(centers,radiiMax,'Color','red');
viscircles(centers,radiiMin,'Color','blue');
hold off
  4 个评论
Jonas
Jonas 2022-11-29
maxbe using the min and max feret is a better possibility since the axes sometimes seem not to be correct:
clear;
im=imread("image.png");
im=rgb2gray(im);
im=im~=0;
im=bwconvhull(im,'objects');
imshow(im)
stats = regionprops('table',im,'Centroid','MajorAxisLength','MinorAxisLength','Orientation');
% check if the results are correct
centers = stats.Centroid;
diametersMax = max([stats.MajorAxisLength stats.MinorAxisLength],[],2);
diametersMin = min([stats.MajorAxisLength stats.MinorAxisLength],[],2);
dxMajor=stats.MajorAxisLength.*cosd(stats.Orientation)./2;
dyMajor=stats.MajorAxisLength.*sind(stats.Orientation)./2;
dxMinor=stats.MinorAxisLength.*sind(stats.Orientation)./2;
dyMinor=stats.MinorAxisLength.*cosd(stats.Orientation)./2;
for nr=1:height(stats)
if stats.Orientation(nr)>0
xcordsMaj(:,nr)=(centers(nr,1)+[+1 -1]*dxMajor(nr))';
ycordsMaj(:,nr)=(centers(nr,2)+[-1 +1]*dyMajor(nr))';
xcordsMin(:,nr)=(centers(nr,1)+[+1 -1]*dxMinor(nr))';
ycordsMin(:,nr)=(centers(nr,2)+[+1 -1]*dyMinor(nr))';
else
xcordsMaj(:,nr)=(centers(nr,1)+[+1 -1]*dxMajor(nr))';
ycordsMaj(:,nr)=(centers(nr,2)+[-1 +1]*dyMajor(nr))';
xcordsMin(:,nr)=(centers(nr,1)+[+1 -1]*dxMinor(nr))';
ycordsMin(:,nr)=(centers(nr,2)+[-1 +1]*dyMinor(nr))';
end
end
line([xcordsMaj xcordsMaj ],[ycordsMaj ycordsMin],'Color','red')
the feret looks like that:
clear;
im=imread("image.png");
im=rgb2gray(im);
im=im~=0;
im=bwconvhull(im,'objects'); % not needed here because ferets are calculated over conv hull; neverthless here for better line visibility
imshow(im)
stats = regionprops('table',im,'MaxFeretProperties','MinFeretProperties');
cellfun(@(in)line(in(:,1),in(:,2),'Color','red'),[stats.MinFeretCoordinates; stats.MaxFeretCoordinates])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Filtering and Enhancement 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by