I’m trying to find out whether user uploaded photo is blur/pixelated. For that i’m using OpenCV4Nodejs package. It only detects blur not the pixelated one. So i found a python code to detect pixelated images but i wanted to do it in node/javascript. I tried converting it but couldn’t as i’m new to python. Can someone help me convert it. if cannot then could you please suggest is there any other way we can detect pixelated images?
Python Code:
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