我曾经尝试过使用二色量化、灰度转换和归一化处理,虽然我不知道它在你的其余图片中的效果如何。
我只是用ImageMagick在命令行上进行了操作,具体如下:
convert input.png +dither -colors 3 -colors 2 -colorspace gray -normalize -scale 250x result.png
在ImageMagick中,一个替代Mark Setchell建议的方法是转向OpenCV。OpenCV具有自适应阈值处理,请参见https://docs.opencv.org/3.3.1/d7/d4d/tutorial_py_thresholding.html和连通组件处理,请参见https://docs.opencv.org/3.1.0/d3/dc0/group__imgproc__shape.html#gac2718a64ade63475425558aa669a943a以及https://www.pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/。
1) convert to grayscale
2) stretch image to full dynamic range
3) apply local (adaptive) thresholding
4) optionally use connected components labelling to remove regions smaller than some total number of pixels (area).
convert 2.png \
-colorspace gray \
-auto-level \
-lat 20x20+10% \
2_lat.gif
convert 19.png \
-colorspace gray \
-auto-level \
-negate \
-lat 20x20+5% \
19_lat.gif
在这里进行可选的连接组件处理:convert 2_lat.gif \
-define connected-components:area-threshold=40 \
-define connected-components:mean-color=true \
-connected-components 4 \
2_lat_ccl.gif
convert 19_lat.gif \
-define connected-components:area-threshold=20 \
-define connected-components:mean-color=true \
-connected-components 4 \
19_lat_ccl.gif
为了使图像更加平滑,您可能需要使用矢量化工具(例如potrace)将栅格图像转换为矢量图像。