A Flask-based web application that transforms photographs into cartoon-style images using advanced image processing techniques with OpenCV. Upload any image and watch it transform into an artistic cartoon version! Features
- Web-based Interface: Clean, intuitive UI with a modern design
- Fast Processing: Real-time image cartoonification using K-means clustering
- Multiple Format Support: Accepts PNG, JPG, and JPEG images
- Edge Detection: Intelligent edge detection using adaptive thresholding
- Color Quantization: Reduces the color palette for an artistic cartoon effect
- Responsive Design: Works seamlessly on desktop and mobile devices
- Dark Theme UI: Modern glassmorphism design with animated background
How It Works The cartoonification process involves:
Grayscale Conversion: Converting the image to grayscale for edge detection Median Blur: Applying blur to reduce noise Edge Detection: Using adaptive thresholding to detect image edges K-means Clustering: Reducing colors to create a simplified, artistic palette Edge Overlay: Combining edges with the color-reduced image for the final cartoon effect
Installation Prerequisites
- Python 3.7 or higher
- pip (Python package manager)
Setup
Clone the repository:
bash git clone https://github.com/anshjain0316/Image-Cartoonifier.git cd Image-Cartoonifier
Create a virtual environment (recommended):
bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
Install dependencies:
bash pip install -r requirements.txt
Usage
- Start the Flask application:
bashpython app.py
- Open your browser and navigate to:
- Select an image from your device
- Click the "Cartoonify!" button
- Download or view the cartoonized result
Project Structure Image-Cartoonifier/ ├── app.py # Flask backend server ├── requirements.txt # Python dependencies ├── templates/ │ └── index.html # Frontend HTML ├── static/ │ ├── style.css # Styling │ ├── script.js # Frontend logic │ └── bg.jpg # Background image ├── uploads/ # Temporary upload folder └── cartoonized_images/ # Output cartoonized images
Technical Details Dependencies
- Flask: Web framework for Python
- OpenCV (cv2): Computer vision library for image processing
- NumPy: Numerical computing library