Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Darkroom

Darkroom restores and colorizes old black-and-white photographs. It removes noise and scratches, repairs faded contrast, and adds realistic color using deep learning.

Live demo: https://huggingface.co/spaces/Nussshra/Darkroom

Darkroom web app

Overview

Darkroom combines image colorization with old-photo restoration.

For colorization I use two models: a pretrained "Colorful Image Colorization" model (Zhang et al., 2016) as a baseline, and a U-Net with a ResNet18 encoder that I fine-tuned on my own set of images. For restoration I built a classical pipeline that denoises, removes scratches, and repairs contrast before the image is colorized.

The whole thing runs as an interactive web app built with Gradio and deployed on Hugging Face Spaces.

How it works

Colorization is done in the Lab color space, which separates lightness (L) from color (a, b). The grayscale image is the L channel; the model predicts a and b, and the three channels are recombined into a color image.

The fine-tuned model uses a ResNet18 encoder pretrained on ImageNet, with a decoder trained to predict the color channels from lightness. Training is self-supervised, it only needs color images, since the color channels are the target and the grayscale is the input.

For old photos, the restoration pipeline cleans the image before colorization: denoising with Non-local Means, scratch removal with morphological detection and inpainting, and contrast repair with a histogram stretch (or CLAHE).

Results

To evaluate restoration objectively, I take clean color images, synthetically age them (fade, blur, noise, scratches), and measure how well the pipeline recovers the original. Across 50 test images:

Method PSNR SSIM
Colorize only 15.28 0.282
Restore + colorize 16.84 0.487

Restoring before colorizing improved SSIM by 0.205 and PSNR by 1.56 dB.

Colorization comparison (grayscale input, pretrained, fine-tuned, original):

Colorization comparison

Restoration stages (input, denoised, descratched, contrast, colorized):

Restoration stages

Installation

git clone https://github.com/Nussshra/Darkroom.git
cd Darkroom
pip install -r requirements.txt
python download_models.py          # downloads the pretrained colorizer weights

Usage

Colorize an image:

python colorize_cli.py photo.jpg --compare

Restore and colorize an old photo (also saves a stage-by-stage montage):

python restore_and_colorize.py old_photo.jpg

Run the web app locally:

pip install -r deploy/requirements.txt
python deploy/app.py

Training

The fine-tuned model can be trained on any folder of color images (no labels required):

pip install -r requirements-train.txt
python train.py --data ./images --epochs 20 --batch-size 16 --size 256
python infer_finetuned.py photo.jpg

A ready-to-run Colab notebook is included as finetune_colab.ipynb.

Evaluation

python evaluate_restoration.py --data ./test_images

This prints the PSNR/SSIM comparison and writes evaluation_results.csv. Add --checkpoint checkpoints/colorization_finetuned.pth to evaluate the fine-tuned model.

Repository structure

.
β”œβ”€β”€ colorizer.py             # pretrained colorizer (OpenCV DNN)
β”œβ”€β”€ colorize_cli.py          # command-line colorizer
β”œβ”€β”€ download_models.py       # downloads the pretrained weights
β”œβ”€β”€ dataset.py               # dataset for fine-tuning
β”œβ”€β”€ model.py                 # ResNet18-encoder U-Net
β”œβ”€β”€ train.py                 # training loop
β”œβ”€β”€ infer_finetuned.py       # inference with the fine-tuned model
β”œβ”€β”€ restore.py               # restoration pipeline
β”œβ”€β”€ degrade.py               # synthetic aging for evaluation
β”œβ”€β”€ evaluate_restoration.py  # PSNR/SSIM benchmark
β”œβ”€β”€ restore_and_colorize.py  # end-to-end CLI
β”œβ”€β”€ deploy/                  # Hugging Face Space (Gradio app)
β”œβ”€β”€ requirements.txt
└── README.md

Acknowledgements

  • Colorful Image Colorization β€” Richard Zhang, Phillip Isola, Alexei A. Efros (ECCV 2016), used as the pretrained baseline.
  • The OpenCV DNN colorization sample.
  • ResNet and ImageNet pretrained weights via torchvision.

License

Released under the MIT License (see LICENSE). The pretrained Zhang et al. model carries its own license terms.

About

Restore and colorize old black and white photos, a classical restoration pipeline feeding transfer-learned deep colorization models. Live demo on πŸ€— Spaces.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages