cat > /workspace/scratch/updateedits.py <<'PY'
import json
p='/workspace/scratch/edits.json';e=json.load(open(p))
e['HH-1041']={'bottom':1038,'solid_small':200,'fg':[
[[139,380],[149,368],[182,359],[223,356],[274,359],[303,368],[313,377],[317,383],[295,387],[167,387]],
[[163,625],[188,620],[233,617],[273,620],[309,629],[327,651],[340,681],[346,710],[340,744],[326,777],[308,814],[279,829],[237,834],[194,830],[158,819],[135,790],[120,752],[116,715],[120,682],[133,652]]
], 'bg':[
[[275,320],[338,315],[346,363],[352,422],[357,472],[350,473],[337,461],[315,451],[314,430],[296,418],[296,393],[324,391],[326,377],[302,362],[274,354]],
[[357,321],[440,320],[440,722],[379,723],[367,527],[368,507],[375,502],[376,490]]
]}
e['HH-8256']={'bottom':1095,'fillholes':True,'fg':[
[[184,107],[211,103],[216,109],[212,126],[212,489],[217,502],[185,502],[181,496],[186,479],[187,135]],
[[130,660],[269,660],[291,687],[308,718],[318,748],[321,775],[317,806],[304,835],[282,855],[254,867],[235,871],[213,875],[181,875],[150,866],[124,850],[104,827],[88,800],[78,772],[78,742],[84,712],[100,686]],
[[168,928],[227,929],[244,943],[271,951],[287,964],[291,983],[302,1000],[324,1022],[330,1035],[325,1046],[320,1050],[318,1080],[298,1088],[244,1092],[173,1092],[120,1087],[81,1077],[80,1048],[71,1041],[71,1028],[91,1007],[108,988],[110,967],[123,952],[150,942]]
]}
e['HH-7150']['fg']=[
[[198,133],[232,132],[233,550],[198,547]],
[[100,482],[137,478],[146,1003],[135,1010],[110,1010],[102,1006]],
[[78,455],[84,439],[116,411],[151,379],[178,346],[195,327],[229,338],[229,362],[208,385],[172,424],[137,452],[115,467],[113,495],[88,500],[80,494]],
[[138,584],[160,557],[236,524],[574,513],[581,573],[584,667],[141,666]],
[[141,664],[298,667],[298,882],[141,877]],
[[386,96],[398,80],[416,71],[432,69],[451,72],[469,85],[482,100],[486,122],[480,145],[466,162],[442,170],[418,166],[400,154],[388,133]],
[[474,74],[500,62],[508,78],[484,95]],
[[640,121],[643,114],[660,113],[666,121],[665,137],[637,135]]
]
e['HH-7150']['bg'] += [
[[0,500],[98,500],[100,1040],[0,1040]],
[[146,452],[195,411],[194,528],[147,558]],
[[178,674],[194,675],[200,874],[180,872]],[[230,675],[244,675],[245,877],[231,875]],
[[468,682],[486,682],[485,883],[469,881]],[[516,683],[537,683],[537,887],[518,886]],[[566,684],[576,684],[575,888],[567,888]]
]
e['HH-4402']['solid_small']=250
# local colour speckle gaps in chair surfaces only
for s in ['HH-4461','HH-9395']:e[s]['solid_small']=30
json.dump(e,open(p,'w'),indent=2)
PY
python /workspace/scratch/updateedits.py
python - <<'PY'
p='/workspace/scratch/applyedits.py';s=open(p).read();s=s.replace(' # Snap boundaries', ''' if e.get('fillholes'):m=ndi.binary_fill_holes(m>127).astype('uint8')*255
 if e.get('solid_small'):
  n,lab,stats,ctr=cv2.connectedComponentsWithStats((m<128).astype('uint8'),8)
  for k in range(1,n):
   if stats[k,4]<e['solid_small']:m[lab==k]=255
 # Snap boundaries''');open(p,'w').write(s)
PY
OPENBLAS_NUM_THREADS=1 python /workspace/scratch/applyedits.py HH-1041 HH-8256 HH-7150 HH-4402