How can i find the Majoraxislength and Minoraxislength of each cell present in binary image ?
7 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
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
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 Center および File Exchange で Image Filtering and Enhancement についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!