Image Colorization Using BrainyPi and Python

by sarav18302 in Circuits > Raspberry Pi

148 Views, 2 Favorites, 0 Comments

Image Colorization Using BrainyPi and Python

bw.png

BrainyPi is a Single Board Computer used by enterprises for implementing Artificial Intelligence in Edge and IoT-based applications which is considered as an alternate to RaspberryPi. In this article, we focus on implementing an image colorization application in BrainyPi using OpenCv and Python.

Usually, the RGB color format is used for analyzing images and . Red, green, and blue light are put together in different ways to create a wide range of colors in the additive RGB color model.

The International Commission on Illumination (CIE) established the CIELAB color space in 1976. It is often referred to as CIE L*a*b* or simply "Lab" color space. It uses three integer values to represent color: L* for lightness and a* and b* for the green-red and blue-yellow hues, respectively. Using these three features, we convert a black and white images into colored images.I am few among those got an early access to BrainyPi and try to experiment my innovative projects

Supplies

brainypi.png
  • BrainyPi
  • Ethernet / WiFi

Log in to BrainyPi Using SSH

Go to Command Prompt and use this command

ssh pi@auth.iotiot.in -p 65530

Install the Dependencies

For this project, we need to install NumPy (for mathematical computations), matplotlib(for image display) and OpenCV(for image processing). Use these commands for installing the dependencies.

pip3 install opencv-python
pip3 install numpy
pip3 install matplotlib

Import the Packages

Import all the necessary packages using the below command.

import numpy as np
import matplotlib.pyplot as plt
import cv2

Define Model Paths & Load the Model

Capture (3).PNG

We use the Caffe model and its corresponding prototxt file to define the model to be used and load them to use them for our application.

Find the Feature "L" and Predict "a" & "B"

Capture1 (3).PNG

We find the feature L from the resized image and sent it to the deep neural network to estimate the values of both " a" and "b".

Creating a Colorized Lab Photo (L + a + B)

Capture1 (5).PNG

Concatenate the L, A, B values to get a colorized LAB image.

Converting to RGB Space

bw.png
color.png

Convert the LAB image to RGB image format to visualize the colorized version of the image.

RGB_colorized = cv2.cvtColor(LAB_colorized, cv2.COLOR_LAB2RGB)
RGB_colorized = np.clip(RGB_colorized, 0, 1)
RGB_colorized = (255 * RGB_colorized).astype("uint8")
plt.imshow(RGB_colorized)
plt.show()

Saving the Colorized Image