Spaces:
Running
Running
import cv2 | |
import numpy as np | |
from registry import registry | |
def original(image): | |
return image | |
def grayscale(image): | |
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
def gaussian_blur(image, kernel_size: int = 15): | |
return cv2.GaussianBlur(image, (kernel_size, kernel_size), 0) | |
def pencil_sketch(image): | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
inverted = cv2.bitwise_not(gray) | |
blurred = cv2.GaussianBlur(inverted, (21, 21), 0) | |
inverted_blurred = cv2.bitwise_not(blurred) | |
return cv2.divide(gray, inverted_blurred, scale=256.0) | |
def sepia(image): | |
kernel = np.array([ | |
[0.393, 0.769, 0.189], | |
[0.349, 0.686, 0.168], | |
[0.272, 0.534, 0.131] | |
]) | |
return cv2.transform(image, kernel) | |
def edge_enhance(image, intensity: float = 1.5): | |
kernel = np.array([ | |
[-1 * intensity, -1 * intensity, -1 * intensity], | |
[-1 * intensity, 9 * intensity, -1 * intensity], | |
[-1 * intensity, -1 * intensity, -1 * intensity] | |
]) | |
return cv2.filter2D(image, -1, kernel) | |
def adjust_contrast(image, alpha: float = 1.5): | |
return cv2.convertScaleAbs(image, alpha=alpha, beta=0) |