python - <<'PY'
p='/workspace/scratch/rugmatte.py';s=open('/workspace/scratch/rugmatte0.py').read();pos=s.index("cv2.imwrite('/workspace/scratch/finalmasks/");s=s[:pos]+'''# At the upper edge, thin upright fibres cross a chart-obscured floorboard.
# A horizontal morphological background estimate removes that board without retouching RGB.
opened=cv2.morphologyEx(a,cv2.MORPH_OPEN,np.ones((1,31),np.uint8))
D2=F-opened
alpha2=np.clip(((a-opened)*D2).sum(2)/((D2*D2).sum(2)+1e-6),0,1)
for y in range(580,645):
 weight=np.clip((645-y)/22,0,1)
 al[y,980:1430]=al[y,980:1430]*(1-weight)+alpha2[y,980:1430]*weight
al[bg]=0;al[al<.045]=0
'''+s[pos:];open(p,'w').write(s)
PY
OPENBLAS_NUM_THREADS=1 python /workspace/scratch/rugmatte.py