我一直在编写一个脚本,基本上我需要它:
使用ImageMagick有一种非常简单的方法(尽管您需要一些Linux实用程序来处理输出文本),但我真的没有看到如何使用Python和PIL执行此操作.
这是我到目前为止所拥有的:
from PIL import Image
image_file = 'test.tiff'
image = Image.open(image_file).convert('L')
histo = image.histogram()
histo_string = ''
for i in histo:
histo_string += str(i) + "\n"
print(histo_string)
Run Code Online (Sandbox Code Playgroud)
这会输出一些内容(我希望对结果进行图形化),但它看起来与ImageMagick输出完全不同.我用这个来检测扫描书的接缝和内容.
感谢任何帮助的人!
我现在有一个(看起来很讨厌的)解决方案,现在:
from PIL import Image
import numpy
def smoothListGaussian(list,degree=5):
window=degree*2-1
weight=numpy.array([1.0]*window)
weightGauss=[]
for i in range(window):
i=i-degree+1
frac=i/float(window)
gauss=1/(numpy.exp((4*(frac))**2))
weightGauss.append(gauss)
weight=numpy.array(weightGauss)*weight
smoothed=[0.0]*(len(list)-window)
for i in range(len(smoothed)):
smoothed[i]=sum(numpy.array(list[i:i+window])*weight)/sum(weight)
return smoothed
image_file = 'verypurple.jpg'
out_file = 'out.tiff'
image = Image.open(image_file).convert('1')
image2 = image.load()
image.save(out_file)
intensities = []
for …
Run Code Online (Sandbox Code Playgroud)