2016-11-14 42 views
1

我正在尋找一種對各種掃描圖像進行批處理圖像處理的好方法。圖像非常大(a4爲300dpi),但圖像處理時間不應該成爲問題。從掃描圖像中刪除背景漸變

一般問題是這樣的:圖像可能有顏色,但不一定非得是,其中一些是黑色和白色。他們在掃描書籍時有相當典型的中間摺痕。我想要的是清除摺疊標記的圖像,它看起來像一個漸變,並且(作爲額外的獎勵)顏色偏移,以便實際背景顯示爲白色/淺灰色。一個例子圖像,這(來源海克爾的Kunstformen der Natur,有興趣的人士):

Scanned Example

我思索與自適應對比度過濾器做在Python中,但並沒有真正拿出好的解決方案之中;幾乎任何框架/工具/語言的輸入都可以幫助我。

+0

你可以添加一些註釋例如,因爲我不明白你想要刪除的內容。 **編輯**好吧,我想我看到它。內部結構的左側部分比右側部分更暗。 – sascha

+0

整個背景顏色不均勻。邊緣變暗;理想情況下,它將更接近具有純色,同時保留細節(請參閱書寫和繪圖)。 – heyarne

+0

你的例子沒有摺痕,你也有嗎? –

回答

1

下面是使用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 

目前仍然有些暈,但似乎降低了,對我來說。

after scale by blur