CAT / CAT.py
jason1987martis's picture
Upload CAT.py
c39d513 verified
Raw History Blame Contribute Delete
1.16 kB
import numpy as np
import cv2
# Function to apply the blending step
def render(img_rgb):
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
img_blur = cv2.GaussianBlur(img_gray, (21, 21), 0, 0) # Gaussian Blur for smoothening
img_blend = cv2.divide(img_gray, img_blur, scale=256) # Blend grayscale with blurred version
return img_blend
# Function to apply gamma correction
def adjust_gamma(image, gamma=1.0):
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255 for i in np.arange(0, 256)]).astype("uint8")
return cv2.LUT(image, table)
# Path to the input and output image
input_image_path = "input.jpg" # Replace with your input image path
output_image_path = "output_sketch.jpg" # Path to save the final CAT-processed image
# Read the input image
image_array = cv2.imread(input_image_path)
# Apply the CAT process
img_blend = render(image_array)
img_gamma = adjust_gamma(img_blend, gamma=.001) # Adjust gamma for better contrast
# Save the processed image
cv2.imwrite(output_image_path, img_gamma)
print(f"Processed image saved successfully at: {output_image_path}")