This project aims to colorize grayscale images with autoencoders. Given a grayscale image, the model should be able to colorize it and we are going to do so with the help of autoencoders.
An autoencoder is a neural networks that are designed to reconstruct the original image. During this process, there might be some reconstruction errors since we take an image and scale it down and then upscale it back to it's original size.
- Choose an appropriate dataset
- Resize the Images to 256*256
- Convert from
RGB --> Lab
colorspace
-
Lab colorspace comprises of 3 channels
- L : Lightness. values range from
1 - 100
- A : represents colors from green to red. values range from
-128 to +128
- B : represents colors from blue to yellow. values range from
-128 to +128
We're using the lab colorspace because we get to isolate the black and white part from the colored part.
- L : Lightness. values range from
- Normalize the images.
- Create the model
- Provide the L channel i.e the monochrome image as the input to the model.
- Get ab channels i.e the colored part of the image as the output.
- Combine the L, a and b channels and convert from Lab to RGB colorspace.
- Evaluate the results.
The model that worked the best for me was trained on the landscape images dataset for 200 epochs on google colab GPU with adam optimiser and 0.1 validation split.
Grayscale Image | Predicted Image | Ground Truth |
---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
There are a few blindspots in the predicted images but overall the model did a pretty good job of coloring the images. The dataset that I used comprised of 7K landscape images. The results highly depend on the nature and size of the dataset so make sure you choose an appropriate one.
Auto Colorization of Black and White Images using Machine Learning “Auto-encoders” technique