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

조회 수: 6 (최근 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 Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by