Counting number of white > 5 Pixel objects in BW image
Mostrar comentarios más antiguos
Hello!
I want to automatically count the particles over 100 microsope images. Due to the sample grind I lost some of my particles and that is why I used the thresholding method according to otsu to make a BW image where my particles and the holes are white and my polymer black. Now im at the "easy part" of counting all the objects. Sadly i just cannot get it running. I tried to delete white pixels for a concentration of less than 5 pixels and simply count with bwlabel the white objects. Is there any other simpler way to count these objects?
please see the attachment.
Thanks!
I found my own solution:
clc
clear all
%Image loading
Oberseite='XXXX';
oFileName=dir(fullfile(Oberseite,'*.png'));
oNumFiles=numel(oFileName);
for k=1:oNumFiles
E=fullfile(Oberseite,oFileName(k).name);
A=imread(E);
oScans{1,k}=A;
BW2 = bwmorph(A,'bridge'); %Bridge unconnected pixels
BW3 = bwareaopen(BW2,5); %Remove objects containing fewer than 5 pixels
BW4 = imfill(BW3,"holes"); %fills holes
[L,Num] = bwlabel(BW4); %Counting white objects in my BW
Anzahl_Oben(:,k) = Num %Sum
F=im2bw(A);
[r, c]= size(F);
Size_Oben=F(1:r,1:c);
%Counting B&W Pixel
nWhite = sum(Size_Oben(:));
nBlack = numel(Size_Oben) - nWhite;
%Area related to the particles
Oben_Flaeche = numel(Size_Oben);
Oben_Partikelanteil(:,k) = nWhite/numel(Size_Oben);
end
Respuesta aceptada
Más respuestas (1)
millercommamatt
el 1 de Dic. de 2022
You should be able to to something like this. I'm waiting on a slow scatter interpolation on my client to finish so I haven't tested this so the syntax might night be quite right, but the idea is.
stats = regionprops(BW); %BW is the array of your binary image
num_object_get5 = sum(stats.Area >= 5);
1 comentario
CJ
el 1 de Dic. de 2022
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!