dylanebert's picture
initial commit
346b70f
raw
history blame contribute delete
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")