使用imagemagick高质量转换图像

时间:2018-01-21 07:46:31

标签: php image-processing imagemagick tesseract

我想从下面显示的图像中删除斑点。我尝试过使用Imagemagick的转换功能,但黑点并未删除。我需要一个带有大胆日期的清晰图像。

Need to remove black dot(Please check using zoom)

2 个答案:

答案 0 :(得分:1)

在Imagemagick中,您可以使用连接的组件和可选的形态去除斑点。例如,以下移除2个像素孤立点或更少。形态填充文本的一些黑暗部分(它删除或打开白色背景)。但它可能会使一些角色合并(触摸):

输入:

enter image description here

convert spots.png \
-threshold 1% -type bilevel \
-define connected-components:area-threshold=2 \
-define connected-components:mean-color=true \
-connected-components 4 \
spots_clean.png

enter image description here

convert spots.png \
-threshold 1% -type bilevel \
-define connected-components:area-threshold=2 \
-define connected-components:mean-color=true \
-connected-components 4 \
-morphology open diamond:1 \
spots_clean_o1.png

enter image description here

convert spots.png \
-threshold 1% -type bilevel \
-define connected-components:area-threshold=2 \
-define connected-components:mean-color=true \
-connected-components 4 \
-morphology open octagon:1 \
spots_clean_o2.png

enter image description here

答案 1 :(得分:0)

我认为没有" easy"这样做的方式。但是:

  1. 您可以迭代图像的所有像素并检查:

    • 如果当前像素是黑色:检查所有neighbourg像素。
    • 如果所有neighbourg像素都是白色,则将当前像素更改为白色。
  2. 更好的方法,但更长的方法是使用OCR来识别数字和字符。然后使用找到的字符重建图像。

相关问题