python - <<'PY'
p='/workspace/scratch/puffinmatte.py';s=open(p).read();start=s.index('B=cv2.morphologyEx');end=s.index('old[1050:]',start)
s=s[:start]+'''B=cv2.GaussianBlur(a,(5,5),1)[bi[0],bi[1]]
D=F-B*((F*B).sum(2)/((B*B).sum(2)+1e-8))[:,:,None]
al=np.clip((a*D).sum(2)/((D*D).sum(2)+1e-8),0,1);al[fg]=1;al[bg]=0;al[al<.03]=0
'''+s[end:];open(p,'w').write(s)
PY
OPENBLAS_NUM_THREADS=1 python /workspace/scratch/puffinmatte.py