Image Colorization Using BrainyPi and Python
by sarav18302 in Circuits > Raspberry Pi
148 Views, 2 Favorites, 0 Comments
Image Colorization Using BrainyPi and Python
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
- 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
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"
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)
Concatenate the L, A, B values to get a colorized LAB image.
Converting to RGB Space
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
Colorized image is saved in the system by these commands
RGB_BGR = cv2.cvtColor(colorized, cv2.COLOR_RGB2BGR)
cv2.imwrite("", RGB_BGR)
Reference:
https://brainypi.com/docs/13-opencv-examples
Further References:
- Colorizing Old B&W Photos and Videos With the Help of AI | by Marcelo Rovai | Towards Data Science
- How to colorize black & white photos with just 100 lines of neural network code | by Emil Wallner | Medium
- Use Raspberry Pi and OpenCV to Visualize Images in Different Color Spaces | Raspberry Pi | Maker Pro
- Black and white image colorization with OpenCV and Deep Learning - PyImageSearch
Credits:
IoTIoT.in - IoTIoT.in: | LinkedIn