function rgb(i) local r = bit32.band(bit32.rshift(i, 16), 255) local g = bit32.band(bit32.rshift(i, 8), 255) local b = bit32.band(i, 255) return r, g, b end function bright(r, g, b) return (r+g+b)/(255*3) end function pixeldiff (u, v) local r1, g1, b1 = rgb(u) local r2, g2, b2 = rgb(v) return bright(math.abs(r1-r2), math.abs(g1-g2), math.abs(b1-b2)) end w, h = img.width, img.height hw, hh = math.floor(w/2), math.floor(h/2) sum = 0 for y=0, hh-1 do for x=0, hw-1 do u = img.getInt(x,y) v = img. getInt(w-1-x, h-1-y) sum = sum+pixeldiff(u, v) end end sym = 1-sum/(hw*hh) return "180° symmetry: "..math.floor(sym*100+0.5).."%"