Spaces:
Runtime error
Runtime error
Download utils.py from michaelj/FastAPI_img2img: direct link, hf CLI and curl.
- Browser
- Download file 359 Bytes
-
https://huggingface.co/spaces/michaelj/FastAPI_img2img/resolve/main/utils.py
- Command line
-
hf download hf://spaces/michaelj/FastAPI_img2img/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/michaelj/FastAPI_img2img/resolve/main/utils.py
359 Bytes
| from PIL import Image | |
| import numpy as np | |
| def replace_background(image: Image.Image, new_background_color=(0, 255, 255)): | |
| image_np = np.array(image) | |
| white_threshold = 255 * 3 | |
| white_pixels = np.sum(image_np, axis=-1) == white_threshold | |
| image_np[white_pixels] = new_background_color | |
| result = Image.fromarray(image_np) | |
| return result | |