Spaces:
Runtime error
Runtime error
Download src/preprocessing/simplifier.py from dylanebert/MeshPalettizer: direct link, hf CLI and curl.
- Browser
- Download file 803 Bytes
-
https://huggingface.co/spaces/dylanebert/MeshPalettizer/resolve/main/src/preprocessing/simplifier.py
- Command line
-
hf download hf://spaces/dylanebert/MeshPalettizer/src/preprocessing/simplifier.py
-
curl -L -o simplifier.py https://huggingface.co/spaces/dylanebert/MeshPalettizer/resolve/main/src/preprocessing/simplifier.py
803 Bytes
| import numpy as np | |
| from PIL import Image | |
| import cv2 | |
| DEFAULT_BILATERAL_D = 9 | |
| DEFAULT_BILATERAL_SIGMA_COLOR = 75 | |
| DEFAULT_BILATERAL_SIGMA_SPACE = 75 | |
| def simplify_texture(image, enabled=True, d=None, sigma_color=None, sigma_space=None): | |
| if not enabled: | |
| return image | |
| if d is None: | |
| d = DEFAULT_BILATERAL_D | |
| if sigma_color is None: | |
| sigma_color = DEFAULT_BILATERAL_SIGMA_COLOR | |
| if sigma_space is None: | |
| sigma_space = DEFAULT_BILATERAL_SIGMA_SPACE | |
| if hasattr(image, "convert"): | |
| rgb_image = image.convert("RGB") | |
| img_array = np.array(rgb_image, dtype=np.uint8) | |
| else: | |
| img_array = np.array(image, dtype=np.uint8) | |
| filtered = cv2.bilateralFilter(img_array, d, sigma_color, sigma_space) | |
| return Image.fromarray(filtered, "RGB") | |