patelritiq/Sketchify
Image-to-pencil-sketch converter using OpenCV. Transforms photos into realistic pencil sketches through grayscale conversion, inversion, Gaussian blur, and division blending.
Sketchify ๐จ
An image-to-pencil-sketch converter using computer vision techniques. Transforms any image into a realistic pencil sketch through grayscale conversion, inversion, Gaussian blur, and division blending.
Project Statistics ๐
- 4 processing steps (Grayscale โ Inversion โ Blur โ Division Blending)
- 3 intermediate visualizations (Grayscale, Inverted, Final Sketch)
- Adjustable sketch intensity (default: 220.0)
- Automatic aspect ratio preservation (max 800x600)
- 21x21 Gaussian kernel for smooth blur effect
- Real-time processing (near-instant for standard images)
Project Overview ๐ฏ
Sketchify is a learning project built while exploring computer vision, image processing, and OpenCV. It demonstrates fundamental image processing techniques to create artistic pencil sketch effects from photographs.
Development Context
- Built as a hands-on learning project for computer vision and image processing
- Explores OpenCV's image manipulation capabilities
- Demonstrates practical application of grayscale conversion, inversion, and blending techniques
- Foundation for understanding digital image processing algorithms
What I Learned
- Grayscale conversion and color space manipulation
- Image inversion techniques
- Gaussian blur for noise reduction
- Division blending for sketch effects
- Aspect ratio preservation during resizing
- OpenCV window management and display
How It Works ๐ง
The sketch conversion process involves 4 key steps:
-
Grayscale Conversion
- Converts RGB image to grayscale
- Reduces color information to intensity values
-
Image Inversion
- Inverts pixel values (255 - pixel_value)
- Creates negative effect
-
Gaussian Blur
- Applies 21x21 Gaussian kernel
- Smooths inverted image
- Reduces noise and creates soft edges
-
Division Blending
- Divides grayscale by inverted blur
- Scale factor: 220.0 (adjustable)
- Produces pencil sketch effect
Real-World Applications ๐
- Artists: Reference sketches for drawing practice
- Social Media: Artistic filters for photos
- Education: Learning tool for image processing concepts
- Fun Projects: Creative photo transformations for kids and hobbyists
Installation & Setup ๐ ๏ธ
Prerequisites
- Python 3.8 or higher
- OpenCV library
Installation
-
Clone the repository:
git clone https://github.com/patelritiq/Sketchify.git cd Sketchify -
Install OpenCV:
pip install opencv-python
Usage ๐
-
Place your image in the project folder
-
Update the image path in
sketch.py:image_path = "your_image.jpg"
-
Run the script:
python sketch.py
-
View the results:
- Original image
- Grayscale version
- Inverted version
- Final pencil sketch
-
Press any key to advance through each stage
Configuration โ๏ธ
You can adjust the sketch intensity by modifying the sketch_intensity variable:
sketch_intensity = 220.0 # Higher = darker sketch, Lower = lighter sketchRecommended values:
- Light sketch: 180-200
- Normal sketch: 220 (default)
- Dark sketch: 240-260
Technical Details ๐ฌ
Image Processing Pipeline
- Input: RGB image (any size)
- Resize: Max 800x600 (maintains aspect ratio)
- Grayscale: BGR to GRAY conversion
- Inversion: 255 - pixel_value
- Blur: Gaussian kernel (21x21, sigma=0)
- Blending: Division with scale factor
- Output: Grayscale pencil sketch
Performance
- Processing Time: Near-instant (<1 second for standard images)
- Memory Usage: Minimal (depends on image size)
- Supported Formats: JPG, PNG, BMP, TIFF (all OpenCV-supported formats)
Limitations โ ๏ธ
- Requires manual image path configuration
- Processes one image at a time
- No automatic saving (displays only)
- Fixed Gaussian kernel size
- Limited to grayscale output
Future Enhancements ๐ฎ
- GUI for user-friendly controls
- Batch processing for multiple images
- Automatic output saving
- Adjustable blur kernel size
- Color sketch options
- Real-time webcam sketching
- Command-line arguments
- Different sketch styles (charcoal, ink, etc.)
Troubleshooting ๐ง
Issue: "Error: Unable to load image"
Solution:
- Ensure image file exists in the project directory
- Check image filename and extension
- Verify image format is supported by OpenCV
Issue: Sketch too light/dark
Solution:
- Adjust
sketch_intensityvariable - Higher values = darker sketch
- Lower values = lighter sketch
Issue: Image too large/small
Solution:
- Modify
max_widthandmax_heightvariables - Default: 800x600 pixels
License ๐
This project is licensed under the MIT License - see the LICENSE file for details.
Author ๐จโ๐ป
Ritik Pratap Singh Patel
- Computer vision and image processing enthusiast
- OpenCV learner
Acknowledgments ๐
This project was developed as a learning exercise in computer vision and image processing using OpenCV. It demonstrates fundamental techniques for artistic image transformation.
Quick Start ๐
# Clone repository
git clone https://github.com/patelritiq/Sketchify.git
cd Sketchify
# Install OpenCV
pip install opencv-python
# Run the program
python sketch.pyTransform your photos into artistic pencil sketches! ๐จโจ