MATLAB: Which mask can I use to count particles in an image

countmaskparticles

Hello, I have this image and I want to count particles in it. I have binarized the image with the code reported below and now I have to count particles. It was told me that I have to find a mask that compare white particles to an objet (maybe a circle) of established dimensions and if the object is contained in the white particles than I can consider it a particle, if is not I go on. What can I use?
clear all
close all
clc
I=imread('dapi_cd105-FGF.jpg');
I2=I(:,:,3);
BW=imbinarize(I2);

Best Answer

There are a number of measures you can do to compare it to a circle, such as the aspect ratio (ask for BoundingBox), Solidity, and circularity (ask for Area and perimeter);
props = regionprops(mask, 'Area', 'Perimeter', 'Solidity', 'BoundingBox');
allAreas = [props.Area];
allPerim = [props.Perimeter];
circularities = allPerim .^2 ./ (4 * pi * allAreas);
bb = vertcat(props.BoundingBox);
aspectRatios = bb(:, 3) ./ bb(:, 4);
Aspect ratios, solidities, and circularities should all be around 1 or so. Anything more than about 2 or 3 is not very circular.