Azzera filtri
Azzera filtri

How can I count the black particles without counting the small particles in the background?

1 visualizzazione (ultimi 30 giorni)
I want to automatically measure the particle size and number, but I can't because of the out-of-round shape and the contrast with the background.
rgb_im = imread('bild_1.jpg');
gray_im = adapthisteq(rgb2gray(rgb_im));
% bw_im = imbinarize(gray_im,'adaptive','ForegroundPolarity','dark','Sensitivity',1);
bw_im2 = ~imbinarize(gray_im,'adaptive','ForegroundPolarity','bright','Sensitivity',1);
bw_im4 = imdilate(bw_im2,strel('disk',1));
BW1 = imfill(bw_im2,'holes');
figure, imshow(BW2)
I have inverted the image and now I want to remove the small black dots from the background. However, I can't get that to work.

Risposta accettata

Antoni Garcia-Herreros
Antoni Garcia-Herreros il 12 Apr 2023
Modificato: Antoni Garcia-Herreros il 12 Apr 2023
Hello loris
Regionprops does exactly what you are looking for.
You can try something like this:
clear all
close all
rgb_im = imread('bild_1.jpg'); %Read RGB image
Error using imread>get_full_filename
File "bild_1.jpg" does not exist.

Error in imread (line 372)
fullname = get_full_filename(filename);
gray_im=rgb2gray(rgb_im); % RGB to grayscale
BW=~imbinarize(gray_im,'adaptive','ForegroundPolarity','bright','Sensitivity',1); %Binarize image
BWao = bwareaopen(BW,20); % Remove particles smaller than 20 pixels
BWaod = imdilate(BWao,strel('disk',2));
m=table2array(r); %Transform table to array
%Filter by cicularity
thr=0.6; % You may change this parameter
Points=m(m(:,4)>thr,:); % Array containing all the Particles
% Points=[Area [pixels], Centroid X, Centroid Y, Circularity, Equiv Diameter ]
hold on
Nparticles=size(Points,1); %Number of Particles
MeanD=mean(Points(:,5)); % Mean Diameter
Hope this helps

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by