How can i find the Majoraxislength and Minoraxislength of each cell present in binary image ?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Respuesta aceptada
Jonas
el 29 de Nov. de 2022
Editada: Jonas
el 29 de Nov. de 2022
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 comentarios
Jonas
el 29 de Nov. de 2022
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])
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Filtering and Enhancement en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!