29 lines
669 B
Python
29 lines
669 B
Python
from PIL import Image
|
|
import sys
|
|
p = sys.argv[1]
|
|
img = Image.open(p).convert("L")
|
|
W, H = img.size
|
|
px = img.load()
|
|
# edge density per row: count |v(x)-v(x-2)| > 40
|
|
rows = []
|
|
for y in range(H):
|
|
c = 0
|
|
for x in range(2, W):
|
|
if abs(px[x, y] - px[x-2, y]) > 45:
|
|
c += 1
|
|
rows.append(c)
|
|
# report top rows grouped
|
|
thr = max(20, sorted(rows)[int(H*0.97)])
|
|
print("W,H", W, H, "row-edge threshold", thr)
|
|
bands = []
|
|
y = 0
|
|
while y < H:
|
|
if rows[y] > thr:
|
|
y0 = y
|
|
while y < H and rows[y] > thr:
|
|
y += 1
|
|
bands.append((y0, y, max(rows[y0:y])))
|
|
y += 1
|
|
for b in bands[:40]:
|
|
print("band y=%d..%d maxedge=%d" % b)
|