# Counts and Sizes of Highly Overlapped/Contacted Particles from Microscopic Image

Dear all below is an image from microscope that I have a hard time doing image processing to get the particle counts and the corresponding sizes (the large one is around 1 micron).

The way I did was following the procedures in another post. But it totally failed probably due to the nature of such highly-overlapped particles. Just wondering is there any way to deal with this type of image? Thanks!

• look at Circular Hough Transform to find circular objects. Apr 15, 2017 at 14:32
• mathematica.stackexchange.com/questions/11725/… Apr 15, 2017 at 14:32
• @AliHashmi I don't think that is a related post. :)
– yode
Apr 19, 2017 at 20:01
• This may be helpful. Apr 19, 2017 at 22:39
• @yode i am not suggesting it is similar. what i wanted was to show that there are things that maybe helpful for example Circular Hough Transform, which if implemented in his case, can account for these particles which are essentially circular Apr 19, 2017 at 22:58

## 2 Answers

The following snippet will allow you to follow the tutorial that you were initially reading using your image instead. The issue, in this case, is not so much the overlapping elements but to correct the noise from a low-light photo to then binarize the image while preserving contour clarity. Using Manipulate at every step can reduce the false positives dramatically. As you can see the number of false positives increases in certain areas of the photo. To deal with the different sizes you could find an appropriate value for the variables kernel and segmentation_X that correspond to a particular particle size in the Serious and Not-So-Serious Image Processing Applications notebook (or simply the third argument of cells in the snippet). It is a good habit to reuse code when that is permitted but it is also fun to come up with solutions from scratch as well. To get more accurate results you could try to use ImagePartition and compound (including errors) the results from the segments in a Mathematica script as it can process smaller pieces of an image faster without the overhead of a graphical user interface that you can later use to refine your results.

hp[img_Image,w_Integer]:=Image[0.5+Subtract@@ImageData/@{img,Blur[img,w]}];
img7= Binarize@Closing[ Threshold[ hp[img,30],0.52],1];
distT =DistanceTransform[img7,Padding->0];
marker = MaxDetect[ImageAdjust[distT],0.02];
w = WatershedComponents[GradientFilter[img7,3],marker,Method->"Rainfall"];Colorize[w]; cells = SelectComponents[w, "Count",500<#<3000&];  measures = ComponentMeasurements[cells,{"Centroid", "EquivalentDiskRadius", "Label"}];Show[img, Graphics[{Orange,Circle@@#&/@(measures[[All,2,1;;2]]), MapThread[Text,{measures[[All,2,3]],measures[[All,2,1]]}]}]]


Max[ComponentMeasurements[cells, "Count"][[All, 1]]]
3549


Here is a slight variation using ImagePartition. The count here was 3,899.

count=0;segments = ImagePartition[img,{250}]; ImageAssemble[ Table[i= Binarize@Closing[ Threshold[ hp[s[[index]],30],0.52],1];
d=DistanceTransform[i,Padding->0];
m = MaxDetect[ImageAdjust[d],0.02];
wa = WatershedComponents[GradientFilter[i,1/10^6],m, Method->"Rainfall"];
Colorize[wa];cells = SelectComponents[wa, "Count",250<#<900&];  measures = ComponentMeasurements[cells,{"Centroid", "EquivalentDiskRadius", "Label"}];
count += Max[ComponentMeasurements[cells, "Count"][[All,1]]];
Show[s[[index]], Graphics[{Orange,Circle@@#&/@(measures[[All,2,1;;2]]), MapThread[Text,{measures[[All,2,3]],measures[[All,2,1]]}]}]]
,{s,segments},{index,1,Last[Length/@segments]}]]


You could also address the different sizes issue with classifiers.

• Well,since nobody post answer,I will give you that 100 rep. :)
– yode
Apr 25, 2017 at 6:45

I have to say this is a challenge tasks in Mathemtica,this answer just a very preliminary start.

img = Import["https://i.stack.imgur.com/QKLHn.jpg"];
mask = MaxDetect[
ImageAdjust[
DistanceTransform[
ColorNegate[
Binarize[ImageAdjust[GradientFilter[img, 2]], .3]]]], .05];
HighlightImage[img, mask]


So as my count,the number of particles is

Max[MorphologicalComponents[mask]]


1129

• Thanks @yode how about the particle size (diameter)? Seems like most of the smaller particle can be captured quite well Apr 14, 2017 at 23:22