app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import numpy as np from skimage import io, color, filters, exposure, img_as_ubyte # Load and convert to grayscale image = io.imread('images/1.webp') gray = color.rgb2gray(image) # Apply Sobel edge detection edges = filters.sobel(gray) # Invert edges inverted = 1 - edges # Improve contrast using histogram equalization or gamma adjustment # Option 1: Histogram Equalization enhanced = exposure.equalize_adapthist(inverted, clip_limit=0.03) # Option 2: Gamma correction (you can try this instead) # enhanced = exposure.adjust_gamma(inverted, gamma=0.5) # Convert to 8-bit and save sketch = img_as_ubyte(enhanced) io.imsave('sketch_darkened.jpg', sketch) |