An open API service indexing awesome lists of open source software.

https://github.com/pn-projects/toonify

A MATLAB app that allows users to upload an image, convert it to a cartoon style, and save the result.
https://github.com/pn-projects/toonify

Last synced: 5 months ago
JSON representation

A MATLAB app that allows users to upload an image, convert it to a cartoon style, and save the result.

Awesome Lists containing this project

README

          

# ๐ŸŽจ Image to Cartoon Converter (Basic Image Processing)

Turn your photos into **cartoon-style images** ๐ŸŽญ using simple **image processing techniques** โ€” no deep learning required, no dataset needed!

We follow the algorithm described in:
> **Shruti Kumari Shrivastava, Ruchi Gajjar**
> *Image Processing based Image to Cartoon Generation: Reducing complexity of large computation arising from Deep Learning*
> IEEE, 2023 International Conference on Computational Intelligence and Sustainable Engineering Solutions (CISES).
> [DOI: 10.1109/CISES58720.2023.10183524]

---

## โœจ Features
- ๐Ÿงน **Noise removal** with Median filter
- โœ‚๏ธ **Edge detection & enhancement** with Canny + Dilation
- ๐ŸŽจ **Color simplification** with Quantization
- ๐Ÿ–ผ๏ธ Outputs a **cartoon-like image** with bold edges and flat colors
- โšก **Lightweight**: runs with OpenCV + NumPy, no GPU or training needed

---

## ๐Ÿงฉ Algorithm Pipeline
Implementation strictly follows the algorithm proposed in the referenced paper:

1. **Input**: Original RGB image
2. **Noise Removal** โ†’ Median Filter (removes salt & pepper noise)
3. **Edge Detection** โ†’ Convert to grayscale + Canny Edge Detector
4. **Edge Enhancement** โ†’ Morphological Dilation (thickens lines)
5. **Image Smoothing** โ†’ Averaging Filter (reduces details for flat colors)
6. **Color Quantization** โ†’
```
NewValue = floor(p / (a-b)) * (a+b)
```
(with constants `a` and `b` controlling number of color bins)
7. **Combine** edges with quantized image โ†’ Final cartoon image

---

## ๐Ÿ“ธ Example Results
Below are the **six outputs** youโ€™ll get when running the code:

| Original | Canny Edges | Thickened Edges |
|----------|-------------|-----------------|
| ![Original](images/original.jpg) | ![Edges](images/canny.jpg) | ![Thickened](images/thickened.jpg) |

| Smoothed | Quantized | Final Cartoon |
|----------|-----------|---------------|
| ![Smoothed](images/smoothed.jpg) | ![Quantized](images/quantized.jpg) | ![Cartoon](images/cartoon.jpg) |

---

## โš™๏ธ Installation & Usage

### Requirements
- Python 3.8+
- [OpenCV](https://pypi.org/project/opencv-python/)
- NumPy
- Matplotlib

Install dependencies:
```bash
pip install opencv-python numpy matplotlib

### Run Script

```bash
python cartoonizer.py
```

Edit the `image_path` variable in `cartoonizer.py` with your image, e.g.:

```python
image_path = "your_photo.jpg"
```

The output will be saved as:

```
your_photo_cartoon.png
```

---

## ๐Ÿ“‚ Project Structure

```
โ”œโ”€โ”€ cartoonizer.py # Main Python script
โ”œโ”€โ”€ README.md # Project documentation
โ”œโ”€โ”€ images/ # Place before/after examples here
โ”‚ โ”œโ”€โ”€ original.jpg
โ”‚ โ”œโ”€โ”€ canny.jpg
โ”‚ โ”œโ”€โ”€ thickened.jpg
โ”‚ โ”œโ”€โ”€ smoothed.jpg
โ”‚ โ”œโ”€โ”€ quantized.jpg
โ”‚ โ””โ”€โ”€ cartoon.jpg

```
## ๐Ÿ“š Reference

* Shruti Kumari Shrivastava, Ruchi Gajjar, *Image Processing based Image to Cartoon Generation: Reducing complexity of large computation arising from Deep Learning*, 2023 IEEE CISES.
DOI: [10.1109/CISES58720.2023.10183524](https://doi.org/10.1109/CISES58720.2023.10183524)

---
## Future Updagrades (coming soon)
A React.js based frontend with proper Anime-like Cartoon generation based on AnimeGAN and other pretrained models