Skip to content

mihir0209/ColourDreams

Repository files navigation

🎨 AI Image Colorization with VGG16# 🌈 Image Colorization with Deep Learning

Transform grayscale images into vibrant color using VGG16 deep learning****Transform grayscale images into vibrant color using Advanced Encoder-Decoder Architecture

VGG16 ColorizationColorization Example

Framework

Python## πŸš€ Quick Start

πŸš€ Quick Start⚑ Fast and easy colorization with pre-trained model

Get started in under 2 minutes!### Getting Started:

  1. οΏ½ Install dependencies: pip install -r requirements.txt

```bash2. πŸš€ Run the app: python app.py

1. Install dependencies3. 🌐 Open browser at http://localhost:5000

pip install -r requirements.txt4. οΏ½ Upload grayscale images

  1. 🌈 Download colorized results

2. Run the application

python app.py## 🎯 Project Overview

3. Open your browser### What it does:

Visit http://localhost:5000- πŸ–ΌοΈ Input: Grayscale images


- 🌈 **Output**: Realistic color images

## ✨ Features

### **Key Features:**

- 🧠 **VGG16 Architecture** - Industry-standard pretrained network- βœ… **Advanced Architecture**: Multi-layer encoder-decoder design

- 🎨 **LAB Color Space** - Perceptually uniform color processing- βœ… **LAB Color Space**: Perceptually uniform color processing

- ⚑ **Fast Inference** - Real-time colorization on GPU/CPU- βœ… **Skip Connections**: Preserves fine details during colorization

- 🌐 **Beautiful Web UI** - Modern, responsive interface- βœ… **Auto-optimization**: Detects hardware and optimizes settings

- πŸ”’ **Privacy First** - Images processed locally, never stored- βœ… **Web Interface**: Flask + Bootstrap frontend



## 🎯 What It Does## πŸ“ **Project Structure**



This application uses the power of deep learning to automatically add realistic colors to black & white images:```

image-colorization/

1. **Upload** a grayscale imageβ”œβ”€β”€ �️ app.py                             # Web interface (Flask)

2. **VGG16** extracts meaningful featuresβ”œβ”€β”€ 🧠 models/                             # Model architecture

3. **Decoder network** predicts color channelsβ”‚   β”œβ”€β”€ colorization_model.py             # Deep encoder-decoder network

4. **Download** your colorized image!β”‚   └── best_tiny_imagenet_colorization_model.pth  # Trained weights

β”œβ”€β”€ πŸ“Š data/                               # Data processing

## πŸ—οΈ Architectureβ”œβ”€β”€ οΏ½ templates/                          # Web UI templates

β”œβ”€β”€ οΏ½ static/                             # CSS and JavaScript

```└── πŸ“‹ requirements.txt                    # Dependencies

Input (Grayscale) β†’ VGG16 Features β†’ Decoder β†’ Color Prediction β†’ Output (Color)```

     [L channel]      [256 filters]    [Upsampling]    [AB channels]    [RGB Image]

```## πŸ–₯️ **Usage**



### Technical Details### **Web Interface:**

```bash

- **Feature Extractor**: VGG16 (pretrained on ImageNet)# Install dependencies

- **Processing**: LAB color space for better perceptual resultspip install -r requirements.txt

- **Input Resolution**: 256x256 (auto-resized)

- **Output**: Full-color RGB image# Run the application

- **Backend**: Flask REST APIpython app.py

- **Frontend**: Modern HTML5/CSS3/JavaScript

# Open browser at http://localhost:5000

## πŸ“¦ Installation```



### Requirements### **Upload and Colorize:**

1. Click "Choose File" to select a grayscale image

- Python 3.8 or higher2. Click "Colorize" to process the image

- PyTorch 2.0+3. View and download the colorized result

- 4GB+ RAM (8GB recommended)

- GPU optional (CUDA support for faster processing)## πŸŽ›οΈ **Technical Details**



### Step-by-Step### **Architecture:**

- **Encoder**: Deep convolutional layers with dilated convolutions

```bash- **Decoder**: Multi-scale feature aggregation with skip connections

# Clone the repository- **Input**: L channel (lightness) from LAB color space

git clone https://github.com/mihir0209/ColourDreams.git- **Output**: AB channels (color) predictions

cd ColourDreams/image-colorization- **Color Space**: LAB for perceptually uniform color representation



# Install dependencies### **Model Specifications:**

pip install -r requirements.txt- **Input Resolution**: 256x256 (automatically resized)

- **Output Resolution**: Matches input resolution

# Run the server- **Processing**: Efficient CPU/GPU inference

python app.py- **Color Accuracy**: Trained on diverse image datasets

🎨 Example Results

🎨 Usage

The model learns to colorize various objects:

Web Interface (Recommended)- 🌸 Flowers: Realistic petal colors

  • 🏞️ Landscapes: Natural sky and vegetation
  1. Start the server: python app.py- πŸ• Animals: Proper fur and eye colors

  2. Open browser: http://localhost:5000- 🏠 Objects: Context-aware colorization

  3. Drag & drop or click to upload an image

  4. Click "Colorize My Image"## πŸ”§ Requirements

  5. Download your colorized result!


### Python APItorch >= 2.0.0

torchvision >= 0.15.0

```pythonnumpy

from inference_pipeline import ColorizationInferencePillow

from PIL import Imagescikit-image

flask

# Initialize modelrequests

colorizer = ColorizationInference()```



# Load image## 🎯 **Features**

img = Image.open('grayscale_photo.jpg')

### **1. 🌐 Web Interface**

# Colorize- Upload images via browser

colorized = colorizer.colorize_image(img)- Real-time colorization

- User-friendly interface

# Save result- Download colorized results

colorized.save('colorized_photo.jpg')

```### **2. 🧠 Advanced Model**

- Deep encoder-decoder architecture

## πŸ› οΈ Project Structure- Skip connections for detail preservation

- LAB color space processing

```- CPU and GPU support

image-colorization/

β”œβ”€β”€ app.py                      # Flask web server### **3. οΏ½ High-Quality Results**

β”œβ”€β”€ inference_pipeline.py       # Inference wrapper- Natural-looking colors

β”œβ”€β”€ models/- Context-aware colorization

β”‚   └── colorization_model.py  # VGG16 + Decoder architecture- Works on various image types

β”œβ”€β”€ templates/

β”‚   └── index.html             # Modern web UI## πŸ“ **Citation**

β”œβ”€β”€ temp_uploads/              # Temporary file storage

└── requirements.txt           # Python dependenciesIf you use this project, please cite:

@misc{image-colorization-2025,

πŸ§ͺ How It Works title={Image Colorization with Deep Learning},

author={Your Name},

1. Color Space Conversion year={2025},

url={https://github.com/mihir0209/ColourDreams}

We use LAB color space instead of RGB:}

  • L channel: Lightness (0-100)```

  • A channel: Green to Red (-128 to 127)

  • B channel: Blue to Yellow (-128 to 127)## πŸ“„ License

This separation allows the model to focus on predicting color (A & B) while preserving the original brightness (L).MIT License - see LICENSE file for details.

2. VGG16 Feature Extraction## 🀝 Contributing

VGG16, pretrained on ImageNet, extracts rich semantic features from the grayscale input. We use layers up to pool3 to maintain spatial resolution.Contributions welcome! Please feel free to submit issues and pull requests.

3. Decoder Network---

A lightweight CNN decoder upsamples the features and predicts the AB color channels using:🌈 Transform your grayscale memories into vibrant color!

  • Convolutional layers for feature transformation
  • Bilinear upsampling for resolution recovery
  • Tanh activation for bounded color predictions

4. RGB Reconstruction

The predicted AB channels are combined with the original L channel and converted back to RGB for display.

πŸ“Š Requirements File

torch>=2.0.0
torchvision>=0.15.0
numpy
Pillow
scikit-image
flask
flask-cors
Werkzeug

πŸŽ“ Model Details

Component Details
Architecture VGG16 + Custom Decoder
Parameters ~15M (decoder only, VGG16 frozen)
Input Size 256Γ—256
Color Space LAB
Framework PyTorch
Inference Time ~0.1s (GPU) / ~0.5s (CPU)

🌟 Example Results

The model can colorize various types of images:

  • πŸ“· Old photographs - Bring family memories to life
  • 🏞️ Landscapes - Natural skies and vegetation
  • πŸ‘€ Portraits - Realistic skin tones
  • πŸ›οΈ Architecture - Context-aware building colors

πŸ”§ API Endpoints

POST /colorize

Upload and colorize an image

Request:

FormData {
  file: <image file>
}

Response:

{
  "status": "success",
  "original_base64": "...",
  "colorized_base64": "...",
  "message": "Image colorized successfully with VGG16"
}

GET /health

Check server status

Response:

{
  "status": "healthy",
  "model_loaded": true
}

GET /model-info

Get model information

Response:

{
  "model_type": "VGG16 Colorization Network",
  "architecture": "VGG16 + Decoder",
  "device": "cuda",
  "input_size": "256x256",
  "color_space": "LAB"
}

πŸ’‘ Tips for Best Results

  • Use clear, well-lit grayscale images
  • Higher resolution inputs generally work better
  • The model works best on natural scenes
  • For best results, images should have good contrast

🚧 Limitations

  • May produce unexpected colors for unusual objects
  • Performance depends on input image quality
  • Not trained specifically for artistic/creative colorization
  • Works best with photographic content

🀝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest features
  • Submit pull requests
  • Improve documentation

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Contact

For questions or feedback:


Made with ❀️ using VGG16 and PyTorch

About

Image colorization using VGG16 for feature extraction and a custom CNN for predicting color channels.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors