This project uses deep learning to automatically colorize black and white images using a pre-trained caffe model.
- Python 3.x
- OpenCV (cv2)
- NumPy
- Matplotlib
-
Install the required packages:
pip install -r requirements.txt
-
Run the setup script that will create or download the required model files:
python setup.py
This script will:
- Create the necessary directories
- Generate the prototxt file locally
- Create the pts_in_hull.npy file
- Try to download the caffemodel file (about 130MB)
If any of these steps fail, the script will provide manual instructions.
-
Alternatively, you can manually set up the project by:
- Running
python create_prototxt.py
to create the prototxt file - Running
python create_pts_in_hull.py
to create the pts_in_hull.npy file - Downloading the caffemodel file from here
- Running
-
Place your black and white images in the
input_images
folder.
To colorize all images in the input_images folder:
python image_colorization.py
To colorize a single image:
python example.py input_images/your_image.jpg output_images/colorized.jpg
The colorized images will be saved in the output_images
folder, and the program will also display the original and colorized images for comparison.
This implementation uses a pre-trained deep learning model that:
- Converts the image to LAB color space
- Predicts the A and B color channels from the L (lightness) channel
- Combines the original L channel with the predicted A and B channels to produce the colorized image
If you encounter issues with the model files:
- Try running the individual scripts:
python create_prototxt.py
python create_pts_in_hull.py
- For the caffemodel file, you may need to manually download it and place it in the project directory.
Based on the project described in the TechVidvan tutorial and uses the model developed by:
- Zhang, R., Isola, P., & Efros, A. A. (2016). Colorful Image Colorization. ECCV.
mkdir -p models images outputs
move colorization_deploy_v2.prototxt models/ move pts_in_hull.npy ./