opsiclear-admin commited on
Commit
458c383
·
verified ·
1 Parent(s): fcbe771

Restore premultiplied alpha preprocessing (matches training data)

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -375,10 +375,9 @@ def preprocess_image(input: Image.Image) -> Image.Image:
375
  size = int(size * 1)
376
  bbox = center[0] - size // 2, center[1] - size // 2, center[0] + size // 2, center[1] + size // 2
377
  output = output.crop(bbox) # type: ignore
378
- output_np = np.array(output)
379
- alpha = output_np[:, :, 3]
380
- output_np[:, :, :3][alpha < 0.05 * 255] = [0, 0, 0]
381
- output = Image.fromarray(output_np[:, :, :3])
382
  return output
383
 
384
 
 
375
  size = int(size * 1)
376
  bbox = center[0] - size // 2, center[1] - size // 2, center[0] + size // 2, center[1] + size // 2
377
  output = output.crop(bbox) # type: ignore
378
+ output = np.array(output).astype(np.float32) / 255
379
+ output = output[:, :, :3] * output[:, :, 3:4]
380
+ output = Image.fromarray((output * 255).astype(np.uint8))
 
381
  return output
382
 
383