This project was developed as part of the "Image Processing and Computer Vision" course at Politecnico di Torino. I chose the topic of black-and-white image colorization to combine my knowledge of OpenCV with a personal goal: colorizing old family photos.
The goal of this study is to use a pre-trained network and compare its results with Photoshop up to November 2024. Additionally, the study explores how various image processing techniques, such as denoising, histogram equalization, and grain removal, affect the colorization process.
This project also provided an opportunity to explore neural networks for the first time. While I am aware that more advanced models exist today, I opted to base my work on the 2016 study "Colorful Image Colorization" for simplicity and to gain a better understanding of foundational approaches in this field.
This project was inspired by the article "Black and White Image Colorization with OpenCV and Deep Learning" published on PyImageSearch.
The code in this repository builds upon the concepts and techniques described in the article, with additional modifications and enhancements to suit specific project goals. Some sections of the code were adapted or derived from examples provided in the article. Please refer to the original article for further details.
-
bw2color_single_image: This script allows users to colorize a single image. It is ideal for those who want to evaluate the effect of the colorization process on a specific image. Simply provide the image path, and the script will output the result.
-
bw2color_image_folder: If you want to colorize multiple images and save the output properly, use the Image Folder Script. This script processes all images in a folder and saves the results accordingly.
-
benchmark_generator: This script allows users to run multiple tests and compare the results in one go. It is useful for benchmarking the effect of different techniques (such as denoising or histogram equalization) on the colorization process. It will automatically generate a comparison of results for easy evaluation.
This project uses argparse to allow you to customize the parameters for the colorization process and apply different image processing techniques. Below are examples of how to run the scripts with various options:
python bw2color_single_image.py --image Images/Input/Full_quality_tiff/scan_1.tif --prototxt model/colorization_deploy_v2.prototxt --model Model/colorization_release_v2.caffemodel --points Model/pts_in_hull.npy
python bw2color_image_folder.py --prototxt model/colorization_deploy_v2.prototxt --model Model/colorization_release_v2.caffemodel --points Model/pts_in_hull.npy --denoise -i Images/Input/Full_quality_png -o Images/Output/Denoise
python bw2color_image_folder.py --prototxt model/colorization_deploy_v2.prototxt --model Model/colorization_release_v2.caffemodel --points Model/pts_in_hull.npy --equalizeHist -i Images/Input/Full_quality_png -o Images/Output/Hist_EQ
python bw2color_image_folder.py --prototxt model/colorization_deploy_v2.prototxt --model Model/colorization_release_v2.caffemodel --points Model/pts_in_hull.npy --removeGrainAndScratches -i Images/Input/Full_quality_png -o Images/Output/Remove_grain_and_scratches
By using argparse, you can choose different configurations based on the image processing techniques you wish to apply, such as denoising, histogram equalization, or grain removal. Make sure to adjust the paths to your input and output directories accordingly.
The pre-trained Caffe model used in this project was downloaded from the description of the video "How to Colorize Black and White Photos in Python".
You must download the model from this drobpox folder to run the network.
Special thanks to the video creator for providing the model and code.
This project is derived from:
- Colorful Image Colorization, licensed under BSD 2-Clause.
The original copyright belongs to Original Authors. The modifications in this repository are licensed under The 2-Clause BSD License.