从扫描图像中删除背景渐变
问题描述:
我正在寻找一种对各种扫描图像进行批处理图像处理的好方法。图像非常大(a4为300dpi),但图像处理时间不应该成为问题。从扫描图像中删除背景渐变
一般问题是这样的:图像可能有颜色,但不一定非得是,其中一些是黑色和白色。他们在扫描书籍时有相当典型的中间折痕。我想要的是清除折叠标记的图像,它看起来像一个渐变,并且(作为额外的奖励)颜色偏移,以便实际背景显示为白色/浅灰色。一个例子图像,这(来源海克尔的Kunstformen der Natur,有兴趣的人士):
我思索与自适应对比度过滤器做在Python中,但并没有真正拿出好的解决方案之中;几乎任何框架/工具/语言的输入都可以帮助我。
答
下面是使用vips的快速入门。它做了一个巨大的模糊(与西格玛200高斯)来获得背景,然后按照它的黑暗量增加图像。
#!/usr/bin/env python
import sys
import gi
gi.require_version('Vips', '8.0')
from gi.repository import Vips
image = Vips.Image.new_from_file(sys.argv[1])
# huge gaussian blur to remove all high frequences ... we will just be left with
# the changes in the background
smooth = image.gaussblur(200)
# scale up the darker areas of the original ... we scale up by the proportion they
# are darker than white by
image *= smooth.max()/smooth
# that'll make rather a dazzling white ... knock it back a bit
image *= 0.9
image.write_to_file(sys.argv[2])
像这样运行:
$ time ./remove_gradient.py ~/Desktop/orig.jpg x.jpg
real 0m16.369s
user 0m55.704s
sys 0m0.218s
目前仍然有些晕,但似乎降低了,对我来说。
你可以添加一些注释例如,因为我不明白你想要删除的内容。 **编辑**好吧,我想我看到它。内部结构的左侧部分比右侧部分更暗。 – sascha
整个背景颜色不均匀。边缘变暗;理想情况下,它将更接近具有纯色,同时保留细节(请参阅书写和绘图)。 – heyarne
你的例子没有折痕,你也有吗? –