import cv2
import numpy as np
from PIL import Image
# Load the image
image_path = "/mnt/data/file-1ZEJNRs1fRw6rjpuCRzwQt"
image = cv2.imread(image_path)
# Convert to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Invert the grayscale image
inverted_image = cv2.bitwise_not(gray_image)
# Apply Gaussian blur
blurred = cv2.GaussianBlur(inverted_image, (21, 21), sigmaX=0, sigmaY=0)
# Invert the blurred image
inverted_blurred = cv2.bitwise_not(blurred)
# Create the pencil sketch
sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
# Save the sketch
sketch_path = "/mnt/data/sketch.png"
cv2.imwrite(sketch_path, sketch)
# Return the path
to the sketch
sketch_path