【问题标题】:Removing highlighted areas when converting pdf to image?将pdf转换为图像时删除突出显示的区域?
【发布时间】:2018-05-23 15:34:44
【问题描述】:

我正在尝试将 pdf 转换为 png,这通常效果很好,但我偶尔会收到 this result

有两个部分被“突出显示”,我不知道为什么,因为 ImageMagick 并没有始终如一地这样做。

这是我正在使用的代码:

with Image(filename=pdf, resolution=200) as src:
     src.background_color = Color('white')
     src.alpha_channel = 'remove'
     images = src.sequence
     Image(images[1]).save(filename='test.png')

我认为透明度可能存在问题,因此前两行与此 question 有关。

我怎样才能让这张图片像这样正常显示 image which looks correct?谢谢!

【问题讨论】:

    标签: python imagemagick wand


    【解决方案1】:

    您遇到的问题是您的输入具有 Alpha 通道。因此,只需移除 Alpha 通道或将其展平在白色上,该区域就会变成灰色,因为它位于底层图像中。

    解决这个问题的最佳方法是使用 ImageMagick -lat 函数。

    http://www.imagemagick.org/script/command-line-options.php#lat

    由于我没有你的原件,我只能处理你生成的 PNG 文件,它显示了这种行为。

    透明输入

    处理

    convert input.png -background white -flatten -negate -lat 25x25+10% -negate result.png
    

    【讨论】:

    • 刚刚测试过,可以在命令行上运行,谢谢!但是,由于我正在处理大量图像(数以万计的程度),是否有等效于 Python 代码中的 -lat 函数?
    • 我在 Python Wand 中看不到这一点。但是 Skimage 中的 threshold_local 看起来很相似,虽然我没有尝试过。见scikit-image.org/docs/dev/api/…。在 docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html 的 OpenCV 中也有自适应阈值,不过我还没有尝试过。
    猜你喜欢
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 2013-11-26
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多