下面是使用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
你的例子沒有摺痕,你也有嗎? –