由于您没有指定工具或操作系统,我将选择安装在大多数 Linux 发行版上并且可用于 OSX 和 Windows 的 ImageMagick。我只是在命令行中使用它,但有可用的 C、C++、Python、Perl、PHP、Ruby、Java 和 .Net 绑定。
我会像这样使用“连接组件分析”或“Blob 分析”:
convert image.png -negate \
-define connected-components:area-threshold=1200 \
-define connected-components:verbose=true \
-connected-components 8 -auto-level result.png
我已经反转了您的图像,-negate
因为在形态学操作中,前景通常是白色而不是黑色。我排除了小于 1200 像素的斑点,因为您的圆圈似乎有 22 像素的半径,这使得面积为 1520 像素 (Pi * 22^2)。
这给出了这个输出,这意味着 7 个 blob - 每行一个 - 具有边界框和每个区域的区域:
Objects (id: bounding-box centroid area mean-color):
0: 1358x1032+0+0 640.8,517.0 1296947 gray(0)
3: 341x350+1017+287 1206.5,468.9 90143 gray(255)
106: 64x424+848+608 892.2,829.3 6854 gray(255)
95: 38x101+44+565 61.5,619.1 2619 gray(255)
49: 17x145+1341+379 1350.3,446.7 2063 gray(0)
64: 43x43+843+443 864.2,464.1 1451 gray(255)
86: 225x11+358+546 484.7,551.9 1379 gray(255)
请注意,由于您的圆圈是 42x42 像素,您将寻找一个方形且接近该大小的斑点 - 所以我正在查看倒数第二行。我可以在您的原始图像上用红色绘制,如下所示:
convert image.png -fill none -stroke red -draw "rectangle 843,443 886,486" result.png

另外,请注意,当您正在寻找一个圆圈时,您希望该区域为pi * r^2
1500 像素或大约 1500 像素,您可以在输出的倒数第二列中检查这一点。
在合理规格的 iMac 上运行 0.4 秒。请注意,您可以将图像分成 4 个并并行运行每个季度以加快速度。所以,如果你做这样的事情:
#!/bin/bash
# Split image into 4 (maybe should allow 23 pixels overlap)
convert image.png -crop 1x4@ tile-%02d.mpc
# Do Blob Analysis on 4 strips in parallel
for f in tile-*mpc; do
convert $f -negate \
-define connected-components:area-threshold=1200 \
-define connected-components:verbose=true \
-connected-components 8 info: &
done
# Wait for all 4 to finish
wait
运行时间约为 0.14 秒。