
Back
July 01, 2024
Computer Vision
Image colorization using Deep learning
pfactorial
Share

Every family possesses at least one black and white photo from some past generation. Many people enjoy seeing how those photos look when colourized. Numerous apps are available for converting black and white photos to colour photos, and AI models have been trained specifically for image colorization. In this blog, we will explore the process of image colorization and use such a model to implement an app for this purpose. Let's delve into how image colorization works.
How Image colorization works
When we first saw a black and white image in our lives, we sensed a noticeable difference, didn't we? But have you ever thought why? It's because we've already been exposed to coloured images, and upon viewing a black and white image, we quickly realise the absence of colour. Our brains hold a wealth of data about coloured images, enabling us to distinguish between black and white and colour images effortlessly.As we see more coloured and black and white images our capability of understanding the difference between a coloured image and a black and white image increases.Similarly when we train an AI model a huge dataset containing black and white images and their corresponding coloured images the model learns to generate a coloured image from a black and white image.When a new balck-and-white image is given as input to the trained model the model will generate a coloured image based on the learned patterns.
Use cases
- Colourizing old black-and-white photos and videos ,providing a more engaging and relatable view of history.
- Enhancing medical images for better interpretation.
- Colorizing black-and-white images of fashion designs or historical fashion trends
Challenges
- Colour mismatch - Colorization models trained on a limited dataset may inaccurately assign colours to objects.
- Training an image colorization model needs good hardware resources.
- Large and diverse image dataset is required for training
Implementing your own image colorization app
Let’s start implementing our Image colorization app using python.
For building the app first we need to clone this repository https://github.com/richzhang/colorization
which contains the trained model for image colorization.
Calling the model
Inside the cloned repository’s main_func.py file there is a function called get_colorized.This function takes an image as input and returns a colourized version of the image using the model eccv16.
How is the model trained?
The code in the repository uses eccv16 ,a model used for image colorization
In the first steps, it looks at the big parts of the picture, like the main shapes and outlines. Then it looks through smaller patterns in the image and tries to predict the colours of pixels.As training progresses the model becomes good at predicting the colours .When a new black and white image is provided to our trained model . The model will return a coloured image by predicting the colours of the pixels.
Building the app
For building the app we are using flask for building the api and html and css for the user interface.
Let’s first build our api.We can use this api to access our model from the user interface
API
Don’t be confused with variables used in the api ,they are added for changing values dynamically in the UI.Those variables are not really important for understanding the api‘s working .Here we are simply taking an image input from the html form and returning the colourized image using the get_colorized function.
App
For the user to access our model we need a user interface. We can create a simple user interface if we know some basic html and css.

In our app ,we need to select the image we want to select using the select image button and we can see the colourized image after clicking the Colorize image button.

Conclusion
In this blog we explored the implementation of an Image colorization app using a pretrained model.Something similar to our implementation is what happens in the backend of most of the image colorization apps.Instead of training a model from scratch we use an existing model to build our app.I hope you learned something new from our blog.
BLOGS
You might also like...

Deep learningData Science Deep Learning+5
Jun 18, 20246 min readRead

Forcast using SARIMAData ScienceE-commerce & Retail+5
Demand Forecasting
Jun 21, 20246 min readRead

Deep learningData ScienceComputer Vision+3
Deepfake
Jun 27, 20247 min readRead

Deep learningData ScienceContent & Media Generation+5
Image deblurring using Generative Adversarial Networks
Jun 27, 20246 min readRead