这是一个相当简单的可行方法:
- 从 x 和 y 方向均平移 1 像素的副本中减去图像。
- 对列和行中的像素求和(我只在下面显示列)。
- 找出峰值位置的频率和标准偏差。
- 如果标准偏差低于某个阈值,则图像会像素化。
第 1 步后的图像:
呈现出清晰的网格图案。现在,如果我们按列对像素求和,我们会得到:
Now if we can figure out the regularity of the peak column spacing, and use this as a threshold to determine if the image is pixelated or not.
这里有一些快速而粗略的 python 代码,用于给出一种方法的想法:
import numpy as np
import Image, ImageChops
im = Image.open('fireworks-pixelate-02.gif')
im2 = im.transform(im.size, Image.AFFINE, (1,0,1,0,1,1))
im3 = ImageChops.subtract(im, im2)
im3 = np.asarray(im3)
im3 = np.sum(im3,axis=0)[:-1]
mean = np.mean(im3)
peak_spacing = np.diff([i for i,v in enumerate(im3) if v > mean*2])
mean_spacing = np.mean(peak_spacing)
std_spacing = np.std(peak_spacing)
print 'mean gap:', mean_spacing, 'std', std_spacing
Output:
mean gap: 14.6944444444 std: 3.23882218342
低标准 = 像素化图像
This unpixelated image:
![enter image description here](https://i.stack.imgur.com/2KAdQ.gif)
有一个对应的图是这样的:
yeilding a much higher std:
mean gap: 16.1666666667 std: 26.8416136293
请注意,“平均差距”毫无意义,因为标准差要高得多。
希望这足以说明这种方法可以很好地发挥作用。