I have several images which show bubbles in water. The task is to identify these bubbles, to count and measure them.
I know this is not easy. 100% accuracy is not needed. The best I have so far is the following:
RidgeFilterV2[img_, \[Sigma]_: 1] := Module[
{data = ImageData[img], Lxx, Lxy, Lyy},
{Lxx, Lxy, Lyy} =
DerivativeFilter[data, {{0, 2}, {1, 1}, {2, 0}}, \[Sigma]];
Image[
Chop[\[Sigma]^(3/2)/2 (Sqrt[(Lxx - Lyy)^2 + 4 Lxy^2] - Lxx - Lyy)]
]
]
TestImage = Import["https://i.imgur.com/pWJAdWv.png"];
ImageTransform[1] = ImageAdjust[TestImage];
ImageTransform[2] = RidgeFilterV2[ImageTransform[1], 3];
ImageTransform[3] = Binarize[ImageTransform[2], 0.008];
ImageTransform[4] = SelectComponents[
ImageTransform[3], {"Circularity", "Area",
"Elongation"}, #1 > 0.3 && #2 > 9 && #3 < 0.7 &];
Visualizing the result:
ImageMultiply[
Colorize[MorphologicalComponents[ImageTransform[4]]], TestImage]
As you can see there are two problems:
- Some of the bubbles get lost completely.
- Many bubbles which are not connected in reality are identifed as one single object.
I would appreciate any hints/ideas to improve my algorithm.
