79493236

Date: 2025-03-07 18:57:42
Score: 1
Natty:
Report link

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

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: sharma margi