Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

Avoid overflow casting to uint8

PENGUINLIONGfdedf86e5679
diff --git a/rembg/sessions/u2net.py b/rembg/sessions/u2net.py
index 9cf8cf6..88922ae 100644
--- a/rembg/sessions/u2net.py
+++ b/rembg/sessions/u2net.py
@@ -41,7 +41,7 @@ class U2netSession(BaseSession):
pred = (pred - mi) / (ma - mi)
pred = np.squeeze(pred)
- mask = Image.fromarray((pred * 255).astype("uint8"), mode="L")
+ mask = Image.fromarray((pred.clip(0, 1) * 255).astype("uint8"), mode="L")
mask = mask.resize(img.size, Image.Resampling.LANCZOS)
return [mask]