Convert Figma logo to code with AI

microsoft logoBringing-Old-Photos-Back-to-Life

Bringing Old Photo Back to Life (CVPR 2020 oral)

15,037
1,983
15,037
105

Top Related Projects

35,503

GFPGAN aims at developing Practical Algorithms for Real-world Face Restoration.

Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration.

[NeurIPS 2022] Towards Robust Blind Face Restoration with Codebook Lookup Transformer

2,395

5,605

Quick Overview

Bringing-Old-Photos-Back-to-Life is a GitHub repository by Microsoft that focuses on restoring and enhancing old, damaged photographs using deep learning techniques. The project aims to repair various types of degradation in historical images, including scratches, color fading, and low resolution, to breathe new life into cherished memories.

Pros

  • Utilizes advanced AI and deep learning techniques for photo restoration
  • Capable of addressing multiple types of image degradation simultaneously
  • Open-source project with potential for community contributions and improvements
  • Provides a valuable tool for preserving historical and personal photographs

Cons

  • May require significant computational resources for processing large or high-resolution images
  • Results can vary depending on the quality and condition of the original photograph
  • Potential for over-processing or introducing artifacts in some cases
  • Limited documentation for non-technical users

Code Examples

# Example 1: Loading and preprocessing an image
from utils import load_image, preprocess_image

image_path = "path/to/old_photo.jpg"
input_image = load_image(image_path)
preprocessed_image = preprocess_image(input_image)
# Example 2: Running the restoration model
from model import OldPhotoRestorer

restorer = OldPhotoRestorer()
restored_image = restorer.restore(preprocessed_image)
# Example 3: Post-processing and saving the result
from utils import postprocess_image, save_image

final_image = postprocess_image(restored_image)
save_image(final_image, "path/to/restored_photo.jpg")

Getting Started

To get started with Bringing-Old-Photos-Back-to-Life:

  1. Clone the repository:

    git clone https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life.git
    cd Bringing-Old-Photos-Back-to-Life
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Download pre-trained models:

    python download_models.py
    
  4. Run the restoration script:

    python run_restoration.py --input_path path/to/old_photo.jpg --output_path path/to/restored_photo.jpg
    

For more detailed instructions and advanced usage, refer to the project's README and documentation.

Competitor Comparisons

35,503

GFPGAN aims at developing Practical Algorithms for Real-world Face Restoration.

Pros of GFPGAN

  • Focuses on face restoration and enhancement, providing better results for facial details
  • Utilizes a pre-trained GAN model, resulting in faster processing times
  • Offers a user-friendly interface and easy-to-use API

Cons of GFPGAN

  • Limited to face restoration, not suitable for full image restoration
  • May produce over-smoothed results in some cases, losing some natural skin texture
  • Requires more computational resources due to the GAN architecture

Code Comparison

GFPGAN:

from gfpgan import GFPGANer

restorer = GFPGANer(model_path='experiments/pretrained_models/GFPGANv1.3.pth', upscale=2)
restored_img, _ = restorer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)

Bringing-Old-Photos-Back-to-Life:

from run_face_enhancement import run_face_enhancement
from run_global import run_global

run_global(input_folder, output_folder)
run_face_enhancement(input_folder, output_folder)

GFPGAN offers a more streamlined API for face restoration, while Bringing-Old-Photos-Back-to-Life provides separate functions for global image restoration and face enhancement. GFPGAN's approach is more focused on face-specific tasks, while Bringing-Old-Photos-Back-to-Life aims for comprehensive image restoration.

Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration.

Pros of Real-ESRGAN

  • More versatile, capable of enhancing various types of images beyond just old photos
  • Offers better performance in terms of processing speed and efficiency
  • Provides pre-trained models for different use cases, allowing for easier implementation

Cons of Real-ESRGAN

  • Less specialized for restoring old or damaged photos specifically
  • May not handle complex artifacts or severe degradation as effectively as Bringing-Old-Photos-Back-to-Life

Code Comparison

Real-ESRGAN:

from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer

model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(scale=4, model_path='path/to/model', model=model)

Bringing-Old-Photos-Back-to-Life:

from Face_Enhancement import face_enhancement
from Global import global_restoration

face_enhancement.process(input_path, output_path)
global_restoration.process(input_path, output_path)

The code snippets demonstrate that Real-ESRGAN focuses on a more general upscaling approach, while Bringing-Old-Photos-Back-to-Life uses separate modules for face enhancement and global restoration, tailored specifically for old photo restoration.

[NeurIPS 2022] Towards Robust Blind Face Restoration with Codebook Lookup Transformer

Pros of CodeFormer

  • More versatile, capable of handling various face restoration tasks beyond old photo restoration
  • Offers a user-friendly web interface for easy usage
  • Provides pre-trained models for quick implementation

Cons of CodeFormer

  • May require more computational resources due to its comprehensive approach
  • Less specialized for specific old photo restoration techniques
  • Potentially slower processing time for large batches of images

Code Comparison

CodeFormer:

from codeformer import CodeFormer
model = CodeFormer()
restored_img = model.restore(input_img)

Bringing-Old-Photos-Back-to-Life:

from bringing_old_photos_back_to_life import OldPhotoRestorer
restorer = OldPhotoRestorer()
restored_img = restorer.restore(input_img)

Both repositories aim to enhance and restore images, but they have different focuses. CodeFormer is a more general-purpose face restoration tool, while Bringing-Old-Photos-Back-to-Life specializes in restoring old, damaged photographs. CodeFormer offers a broader range of applications but may be less optimized for specific old photo restoration tasks. Bringing-Old-Photos-Back-to-Life, on the other hand, is tailored for old photo restoration but may have limited versatility for other image enhancement tasks.

2,395

Pros of GPEN

  • Focuses specifically on face restoration and enhancement
  • Utilizes a generative adversarial network (GAN) for high-quality results
  • Faster processing time for single-face images

Cons of GPEN

  • Limited to face restoration, not full photo reconstruction
  • May struggle with severely damaged or low-quality input images
  • Less flexibility for handling diverse types of old photos

Code Comparison

GPEN:

from gpen import FaceRestorer

restorer = FaceRestorer()
restored_face = restorer.process(input_image)

Bringing-Old-Photos-Back-to-Life:

from bringing_old_photos_back_to_life import PhotoRestorer

restorer = PhotoRestorer()
restored_photo = restorer.restore(input_image)

Both repositories offer Python-based implementations for photo restoration, but GPEN focuses on face-specific restoration, while Bringing-Old-Photos-Back-to-Life provides a more comprehensive solution for entire photo reconstruction.

GPEN is better suited for projects requiring quick and high-quality face enhancements, while Bringing-Old-Photos-Back-to-Life offers a more versatile approach for restoring various types of old photographs, including landscapes and group photos.

The choice between the two depends on the specific requirements of your project, such as the types of images you're working with and the desired level of restoration for different elements within the photos.

5,605

Pros of ailab

  • More comprehensive AI capabilities beyond photo restoration
  • Active development with frequent updates
  • Larger community and user base due to Bilibili's popularity

Cons of ailab

  • Less focused on specific photo restoration techniques
  • May require more computational resources for broader AI tasks
  • Documentation primarily in Chinese, which may be a barrier for some users

Code Comparison

Bringing-Old-Photos-Back-to-Life:

def run_cmd(command):
    res = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    return res.stdout.decode('utf-8')

ailab:

def process_image(image_path):
    img = cv2.imread(image_path)
    processed = ai_model.enhance(img)
    return processed

The code snippets show different approaches:

  • Bringing-Old-Photos-Back-to-Life focuses on running external commands
  • ailab demonstrates direct image processing using AI models

Both repositories offer valuable tools for image enhancement, but they cater to different needs. Bringing-Old-Photos-Back-to-Life is more specialized in photo restoration, while ailab provides a broader range of AI capabilities. The choice between them depends on the specific requirements of the user and their familiarity with the respective ecosystems.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Old Photo Restoration (Official PyTorch Implementation)

Project Page | Paper (CVPR version) | Paper (Journal version) | Pretrained Model | Colab Demo | Replicate Demo & Docker Image :fire:

Bringing Old Photos Back to Life, CVPR2020 (Oral)

Old Photo Restoration via Deep Latent Space Translation, TPAMI 2022

Ziyu Wan1, Bo Zhang2, Dongdong Chen3, Pan Zhang4, Dong Chen2, Jing Liao1, Fang Wen2
1City University of Hong Kong, 2Microsoft Research Asia, 3Microsoft Cloud AI, 4USTC

:sparkles: News

2022.3.31: Our new work regarding old film restoration will be published in CVPR 2022. For more details, please refer to the project website and github repo.

The framework now supports the restoration of high-resolution input.

Training code is available and welcome to have a try and learn the training details.

You can now play with our Colab and try it on your photos.

Requirement

The code is tested on Ubuntu with Nvidia GPUs and CUDA installed. Python>=3.6 is required to run the code.

Installation

Clone the Synchronized-BatchNorm-PyTorch repository for

cd Face_Enhancement/models/networks/
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../../
cd Global/detection_models
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../

Download the landmark detection pretrained model

cd Face_Detection/
wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
bzip2 -d shape_predictor_68_face_landmarks.dat.bz2
cd ../

Download the pretrained model, put the file Face_Enhancement/checkpoints.zip under ./Face_Enhancement, and put the file Global/checkpoints.zip under ./Global. Then unzip them respectively.

cd Face_Enhancement/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/face_checkpoints.zip
unzip face_checkpoints.zip
cd ../
cd Global/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/global_checkpoints.zip
unzip global_checkpoints.zip
cd ../

Install dependencies:

pip install -r requirements.txt

:rocket: How to use?

Note: GPU can be set 0 or 0,1,2 or 0,2; use -1 for CPU

1) Full Pipeline

You could easily restore the old photos with one simple command after installation and downloading the pretrained model.

For images without scratches:

python run.py --input_folder [test_image_folder_path] \
              --output_folder [output_path] \
              --GPU 0

For scratched images:

python run.py --input_folder [test_image_folder_path] \
              --output_folder [output_path] \
              --GPU 0 \
              --with_scratch

For high-resolution images with scratches:

python run.py --input_folder [test_image_folder_path] \
              --output_folder [output_path] \
              --GPU 0 \
              --with_scratch \
              --HR

Note: Please try to use the absolute path. The final results will be saved in ./output_path/final_output/. You could also check the produced results of different steps in output_path.

2) Scratch Detection

Currently we don't plan to release the scratched old photos dataset with labels directly. If you want to get the paired data, you could use our pretrained model to test the collected images to obtain the labels.

cd Global/
python detection.py --test_path [test_image_folder_path] \
                    --output_dir [output_path] \
                    --input_size [resize_256|full_size|scale_256]

3) Global Restoration

A triplet domain translation network is proposed to solve both structured degradation and unstructured degradation of old photos.

cd Global/
python test.py --Scratch_and_Quality_restore \
               --test_input [test_image_folder_path] \
               --test_mask [corresponding mask] \
               --outputs_dir [output_path]

python test.py --Quality_restore \
               --test_input [test_image_folder_path] \
               --outputs_dir [output_path]

4) Face Enhancement

We use a progressive generator to refine the face regions of old photos. More details could be found in our journal submission and ./Face_Enhancement folder.

NOTE: This repo is mainly for research purpose and we have not yet optimized the running performance.

Since the model is pretrained with 256*256 images, the model may not work ideally for arbitrary resolution.

5) GUI

A user-friendly GUI which takes input of image by user and shows result in respective window.

How it works:

  1. Run GUI.py file.
  2. Click browse and select your image from test_images/old_w_scratch folder to remove scratches.
  3. Click Modify Photo button.
  4. Wait for a while and see results on GUI window.
  5. Exit window by clicking Exit Window and get your result image in output folder.

How to train?

1) Create Training File

Put the folders of VOC dataset, collected old photos (e.g., Real_L_old and Real_RGB_old) into one shared folder. Then

cd Global/data/
python Create_Bigfile.py

Note: Remember to modify the code based on your own environment.

2) Train the VAEs of domain A and domain B respectively

cd ..
python train_domain_A.py --use_v2_degradation --continue_train --training_dataset domain_A --name domainA_SR_old_photos --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 100 --no_html --gpu_ids 0,1,2,3 --self_gen --nThreads 4 --n_downsample_global 3 --k_size 4 --use_v2 --mc 64 --start_r 1 --kl 1 --no_cgan --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder]

python train_domain_B.py --continue_train --training_dataset domain_B --name domainB_old_photos --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder]  --no_instance --resize_or_crop crop_only --batchSize 120 --no_html --gpu_ids 0,1,2,3 --self_gen --nThreads 4 --n_downsample_global 3 --k_size 4 --use_v2 --mc 64 --start_r 1 --kl 1 --no_cgan --outputs_dir [your_output_folder]  --checkpoints_dir [your_ckpt_folder]

Note: For the --name option, please ensure your experiment name contains "domainA" or "domainB", which will be used to select different dataset.

3) Train the mapping network between domains

Train the mapping without scratches:

python train_mapping.py --use_v2_degradation --training_dataset mapping --use_vae_which_epoch 200 --continue_train --name mapping_quality --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 80 --no_html --gpu_ids 0,1,2,3 --nThreads 8 --load_pretrainA [ckpt_of_domainA_SR_old_photos] --load_pretrainB [ckpt_of_domainB_old_photos] --l2_feat 60 --n_downsample_global 3 --mc 64 --k_size 4 --start_r 1 --mapping_n_block 6 --map_mc 512 --use_l1_feat --niter 150 --niter_decay 100 --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder]

Traing the mapping with scraches:

python train_mapping.py --no_TTUR --NL_res --random_hole --use_SN --correlation_renormalize --training_dataset mapping --NL_use_mask --NL_fusion_method combine --non_local Setting_42 --use_v2_degradation --use_vae_which_epoch 200 --continue_train --name mapping_scratch --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 36 --no_html --gpu_ids 0,1,2,3 --nThreads 8 --load_pretrainA [ckpt_of_domainA_SR_old_photos] --load_pretrainB [ckpt_of_domainB_old_photos] --l2_feat 60 --n_downsample_global 3 --mc 64 --k_size 4 --start_r 1 --mapping_n_block 6 --map_mc 512 --use_l1_feat --niter 150 --niter_decay 100 --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder] --irregular_mask [absolute_path_of_mask_file]

Traing the mapping with scraches (Multi-Scale Patch Attention for HR input):

python train_mapping.py --no_TTUR --NL_res --random_hole --use_SN --correlation_renormalize --training_dataset mapping --NL_use_mask --NL_fusion_method combine --non_local Setting_42 --use_v2_degradation --use_vae_which_epoch 200 --continue_train --name mapping_Patch_Attention --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 36 --no_html --gpu_ids 0,1,2,3 --nThreads 8 --load_pretrainA [ckpt_of_domainA_SR_old_photos] --load_pretrainB [ckpt_of_domainB_old_photos] --l2_feat 60 --n_downsample_global 3 --mc 64 --k_size 4 --start_r 1 --mapping_n_block 6 --map_mc 512 --use_l1_feat --niter 150 --niter_decay 100 --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder] --irregular_mask [absolute_path_of_mask_file] --mapping_exp 1

Citation

If you find our work useful for your research, please consider citing the following papers :)

@inproceedings{wan2020bringing,
title={Bringing Old Photos Back to Life},
author={Wan, Ziyu and Zhang, Bo and Chen, Dongdong and Zhang, Pan and Chen, Dong and Liao, Jing and Wen, Fang},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={2747--2757},
year={2020}
}
@article{wan2020old,
  title={Old Photo Restoration via Deep Latent Space Translation},
  author={Wan, Ziyu and Zhang, Bo and Chen, Dongdong and Zhang, Pan and Chen, Dong and Liao, Jing and Wen, Fang},
  journal={arXiv preprint arXiv:2009.07047},
  year={2020}
}

If you are also interested in the legacy photo/video colorization, please refer to this work.

Maintenance

This project is currently maintained by Ziyu Wan and is for academic research use only. If you have any questions, feel free to contact raywzy@gmail.com.

License

The codes and the pretrained model in this repository are under the MIT license as specified by the LICENSE file. We use our labeled dataset to train the scratch detection model.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.