Transform your old black and white photos into vibrant colored images using the power of deep learning! This project uses an advanced neural network to automatically predict and apply realistic colors to grayscale images.
This colorization tool brings old memories back to life by automatically adding colors to black and white photographs. Using a pre-trained deep learning model based on the research paper "Colorful Image Colorization" by Zhang et al., this project can intelligently predict what colors should be applied to different parts of an image.
The algorithm analyzes the content of the image (people, objects, landscapes) and applies colors based on patterns learned from millions of colored images during training.
- Automatic Colorization - No manual work required, just run the script
- Batch Processing - Colorize multiple images at once
- Side-by-Side View - Compare original and colorized images instantly
- Easy to Use - Simple Python script with clear instructions
- Pre-trained Model - Uses state-of-the-art colorization algorithm
See the magic in action! Below are some examples of black and white images that have been automatically colorized:
The legendary physicist vintage B&W photo, now in color!
The brilliant inventor brought to life with color
Capturing childhood memories in vibrant colors
Vintage cars look stunning when colorized
Various subjects can be automatically colorized
Before running the project, make sure you have:
- Python 3.6 or higher
- OpenCV library
- NumPy library
Follow these simple steps to get started:
git clone https://github.com/YOUR_USERNAME/image-colorization.git
cd image-colorizationpip install opencv-python numpyOr install from requirements file:
pip install -r requirements.txtDownload these three files and place them in the model/ folder:
colorization_deploy_v2.prototxtcolorization_release_v2.caffemodel(125 MB)pts_in_hull.npy
Download Links:
- GitHub Repository: https://github.com/richzhang/colorization/tree/caffe/colorization/models
- Direct Download: colorization_release_v2.caffemodel
- Place your black and white image in the project folder
- Open
main.pyand modify this line:input_img = "your_image.jpg" # Change to your image name
- Run the script:
python main.py
- Find your colorized image saved as
output_colorized.jpg - A preview window will also show the before/after comparison
- Create a folder named
input_imagesin the project directory - Place all your black and white images inside this folder
- Run the script:
python main.py
- All colorized images will be saved in the
output_images/folder with the prefix "colorized_"
image-colorization/
│
├── main.py # Main colorization script
├── README.md # Project documentation (this file)
├── requirements.txt # Python dependencies
│
├── model/ # Model files (download separately)
│ ├── colorization_deploy_v2.prototxt
│ ├── colorization_release_v2.caffemodel
│ └── pts_in_hull.npy
│
├── examples/ # Example before/after images
│ ├── Einstein.png
│ ├── Tesla.png
│ ├── kid.jpg
│ ├── car.png
│ └── Image.jpg
│
├── input_images/ # Place your images here for batch processing
└── output_images/ # Colorized results will be saved here
The colorization process follows these steps:
- Input Processing: The grayscale image is converted to LAB color space
- Lightness Extraction: The L channel (lightness) is separated from the image
- Neural Network Prediction: A deep convolutional neural network predicts the A and B color channels
- Color Reconstruction: The predicted color channels are combined with the original lightness
- Output Conversion: The image is converted back to RGB format and saved
The neural network was trained on over 1 million images and learned to associate objects, textures, and scenes with appropriate colors.
- Model Architecture: CNN-based encoder-decoder network
- Color Space: LAB (perceptually uniform color space)
- Input Size: 224x224 pixels (resized internally)
- Framework: Caffe (via OpenCV DNN module)
- Output Format: BGR color image (OpenCV standard)
The colorization works best on:
- Historical photographs of people
- Portraits and faces
- Natural landscapes and outdoor scenes
- Animals and wildlife
- Vintage cars and architecture
May not work as well on:
- Abstract art or graphics
- Very low quality or damaged images
- Images with unusual or artistic content
- Text-heavy documents
Solution:
- Verify all three model files are in the
model/folder - Check that file names match exactly (case-sensitive)
- Re-download files if they seem corrupted
Solution:
- Ensure the image file exists in the specified location
- Check that the file extension is supported (jpg, png, bmp)
- Try using an absolute path instead of relative path
Solution:
- The model works best on natural photos
- Try different images with clearer subjects
- Ensure the input image has good contrast
- Some images may require manual touch-ups after colorization
Solution:
- First run loads the model, which takes time
- Subsequent colorizations will be faster
- Large images take longer to process
- Consider resizing very large images before processing
This project is based on the groundbreaking research:
Paper: "Colorful Image Colorization"
Authors: Richard Zhang, Phillip Isola, Alexei A. Efros
Institution: University of California, Berkeley
Published: ECCV 2016
Paper Link: https://arxiv.org/abs/1603.08511
Original Implementation: https://github.com/richzhang/colorization
HADI SARHANGI FARD
Feel free to reach out for questions, suggestions, or collaborations!
- find me in linkedin: www.linkedin.com/in/hadi-sarhangi-fard-mech-eng
This project is open source and available for educational and research purposes.
The pre-trained model is provided by the original authors and is subject to their license terms.
Contributions are welcome! If you have ideas for improvements:
- Fork the repository
- Create a new branch (
git checkout -b feature-improvement) - Make your changes
- Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature-improvement) - Create a Pull Request
Ideas for future development:
- Add a graphical user interface (GUI)
- Support for video colorization
- Real-time colorization with webcam
- Multiple model options for different styles
- Color intensity adjustment slider
- Option to manually adjust colors in specific regions
- Export to different image formats
- Mobile app version
If you found this project helpful or interesting, please consider giving it a star on GitHub! It helps others discover the project and motivates further development.
Have questions or feedback? Feel free to:
- Open an issue on GitHub
- Submit a pull request with improvements
- Share your colorization results!
** Happy Colorizing! **
Bringing the past to life, one image at a time.




