Enhancing Low-Light images using MIRNet | by Himanshu Sharma | Towards Data Science

All of us have clicked a lot of images in our lifespan but the one issue that I particularly have faced and I am sure you all must have experienced is clicking images in low light. If you don’t have night vision or a very high-end camera the images can be very blurry or have very low light which makes the content in that image almost invisible.
Now if you don’t have a night vision camera and you are fond of taking pictures then this article is for you because in this article I will show you how you can enhance all your low-light images to make them properly visible. So let’s get started.
In this article, we will be using the MIRNet model for image enhancement. It is used for the enhancement of low-light images, it is a pre-trained model that can be easily downloaded from the Github repo. For this article, I am using Saumik Rakshit’s GitHub repo.
For this article, we will be using Google Collab. For initial setup, we need to open a collab notebook and clone the required Github repository using the command below:
!git clone https://github.com/soumik12345/MIRNet#Setting up current directory%cd MIRNet
Wandb is used to organize and analyze machine learning experiments. It is framework-agnostic and lighter than TensorBoard. Each time when we run a script using wandb, the hyperparameters, and output metrics are saved which can be further visualized. We will install it by running the below-given command.
!pip install -q wandb
The next important step is to import all the libraries which will be required for this project.
from glob import glob  #from PIL import Image  #For image operationsfrom matplotlib import pyplot as plt #for visualization# Importing required dependencies from MIRNetfrom mirnet.inference import Infererfrom mirnet.utils import download_dataset, plot_resultimport tensorflow as tf # For modellingimport numpy as np # For mathematical computation
In this step, we will be downloading the data for the model and the predefined weights. This will create the model with the required pre-trained weights for our project which is an image enhancement. By running the below-given command we will complete this step.
inferer = Inferer()inferer.download_weights('1sUlRD5MTRKKGxtqyYDpTv7T3jOW6aVAL')inferer.build_model(num_rrg=3, num_mrb=2, channels=64,      weights_path='low_light_weights_best.h5')inferer.model.summary()
Next, we will load the weights into the model and save the model. Below given command will solve the purpose.
inferer.model.save('mirnet')
Now we need to load an image into google collab so that we can use it for enhancement.
IMAGE_LOC = '/content/123.JPG'  # change the name of image to you desired image 
This is the final step in which we will pass our input image to the model and the model will generate the enhanced output image. The code given below works for that.
original_image, output_image = inferer.infer(IMAGE_LOC)plot_result(original_image, output_image)
Here, you can clearly see how our model enhanced a low light image to a clearly visible image.
Go ahead try this with different images, in case you find any difficulty you can post that in the response section.
This post is in collaboration with Piyush Ingale
Thanks for reading! If you want to get in touch with me, feel free to reach me on hmix13@gmail.com or my LinkedIn Profile. You can view my Github profile for different data science projects and packages tutorials. Also, feel free to explore my profile and read different articles I have written related to Data Science.