python - <<'PY'
p='/workspace/scratch/rugmatte.py';s=open(p).read();s=s.replace('al[bg]=0;al[al<.045]=0','''edge=(~fg)&(~bg)
# Sparse downward tips are also separated from board grain by the horizontal opening.
for y in range(940,1035):
 weight=np.clip((y-970)/25,0,1)
 al[y]=al[y]*(1-weight)+alpha2[y]*weight
al[fg]=1;al[edge & ((a-B).mean(2)<.002)]=0
al[bg]=0;al[al<.045]=0''');open(p,'w').write(s)
PY
OPENBLAS_NUM_THREADS=1 python /workspace/scratch/rugmatte.py
python - <<'PY'
import cv2,numpy as np
from scipy import ndimage as ndi
s='HH-1041';p='/workspace/scratch/finalmasks/'+s+'.png';m=cv2.imread(p,0);fill=ndi.binary_fill_holes(m>127);z=np.indices(m.shape)[0]>1170;m[fill&z]=255;cv2.imwrite(p,m)
PY