How can I count the black particles without counting the small particles in the background?
4 次查看(过去 30 天)
显示 更早的评论
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');
BW2=255-BW1;
figure, imshow(BW2)
imshowpair(BW1,BW2,'montage')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1353019/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1353024/image.jpeg)
0 个评论
采纳的回答
Antoni Garcia-Herreros
2023-4-12
编辑:Antoni Garcia-Herreros
2023-4-12
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
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));
BWaodf=imfill(BWaod,'holes');
r=regionprops('table',BWaodf,'Centroid','Area','Circularity','EquivDiameter');
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 ]
imshow(rgb_im)
hold on
viscircles([Points(:,2),Points(:,3)],Points(:,5)*0.5,'LineWidth',0.5);
Nparticles=size(Points,1); %Number of Particles
MeanD=mean(Points(:,5)); % Mean Diameter
Hope this helps
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!