import sys
import numpy as np
from PIL import Image
img = sys.argv[1]
x0,y0,x1,y1,thr = [int(v) for v in sys.argv[2:7]]
a = np.asarray(Image.open(img).convert('RGB'), dtype=np.float32).mean(axis=2)
m = a < thr
sub = m[y0:y1, x0:x1]
rows = sub.any(axis=1)
bands=[]; s=None
for i,v in enumerate(rows):
    if v and s is None: s=i
    if not v and s is not None:
        bands.append((y0+s, y0+i-1)); s=None
if s is not None: bands.append((y0+s, y0+len(rows)-1))
for b in bands:
    seg = sub[b[0]-y0:b[1]-y0+1]
    cols = np.where(seg.any(axis=0))[0]
    print(f"y{b[0]}-{b[1]} h{b[1]-b[0]+1}  x{x0+cols.min()}-{x0+cols.max()} w{cols.max()-cols.min()+1}")
