A Programmer’s Perfect Father’s Birthday Gift: A Restored Old Photo

Manoj Kumar
3 min readJul 8, 2021

--

Everyone’s family has some old photos filed away in an album. Despite the simple backgrounds and casual poses, these photos reveal quite a bit, telling stories and providing insight on what life was like in the past.

In anticipation of Father’s Birthday, John, a programmer at Huawei, was racking his brains about what gift to get for his father. He thought about it for quite a while — then suddenly, a glimpse at an old photo album piqued his interest. “Why not using my coding expertise to restore my father’s old photo, and shed light on his youthful personality?”, he mused. Intrigued by this thought, John started to look into how he could achieve this goal.

Image super-resolution in HUAWEI ML Kit was ultimately what he settled on. With this service, John was able to convert the wrinkled and blurry old photo into a hi-res image, and presented it to his father. His father was deeply touched by the gesture.

Actual Effects:

Image Super-Resolution

This service converts an unclear, low-resolution image into a high-resolution image, increasing pixel intensity and displaying details that were missed when the image was originally taken.

Image super-resolution is ideal in computer vision, where it can help enhance image recognition and analysis capabilities. The Image super-resolution technology has improved rapidly, and weighs more in day-to-day work and life. It can be used to sharpen common images, such as portrait shots, as well as vital images in fields like medical imaging, security surveillance, and satellite imaging.

Image super-resolution offers both 1x and 3x super-resolution capabilities. 1x super-resolution removes compression noise, and 3x super-resolution effectively suppresses compression noise, while also providing a 3x enlargement capability.

The Image super-resolution service can help enhance images for a wide range of objects and items, such as greenery, food, and employee ID cards. You can even use it to enhance low-quality images such as news images obtained from the network into clear, enlarged ones.

Development Preparations

For more details about configuring the Huawei Maven repository and integrating the image super-resolution SDK, please refer to the Development Guide of ML Kit on HUAWEI Developers.

Configuring the Integrated SDK

Open the build.gradle file in the app directory. Add build dependencies for the image super-resolution SDK under the dependencies block

Configuring the AndroidManifest.xml File

Open the AndroidManifest.xml file in the main folder. Apply for the storage read permission as needed by adding the following statement before <application>:

Add the following statements in <application>. Then the app, after being installed, will automatically update the machine learning model to the device

Development Procedure

Configuring the Application for the Storage Read Permission

Check whether the app has had the storage read permission in onCreate() of MainActivity. If no, apply for this permission through requestPermissions; if yes, call startSuperResolutionActivity() to start super-resolution processing on the image.

Check the permission application results:

After the application is complete, create a button. Set a configuration that after the button is tapped, the app will read images from the storage.

Configuring the Image Super-Resolution Analyzer

Before the app can perform super-resolution processing on the image, create and configure an analyzer. The example below configures two parameters for the 1x super-resolution capability and 3x super-resolution capability respectively. Which one of them is used depends on the value of selectItem.

Constructing and Processing the Image

Before the app can perform super-resolution processing on the image, convert the image into a bitmap whose color format is ARGB8888. Create an MLFrame object using the bitmap. After the image is added, obtain its information and override onActivityResult.

Create an MLFrame object using the bitmap.

Call the asynchronous method asyncAnalyseFrame to perform super-resolution processing on the image.

After the recognition is complete, stop the analyzer.

Meanwhile, override onDestroy of the activity to release the bitmap resources.

References

To learn more, please visit:

>> Official webpages for Image Super-Resolution and ML Kit

>> HUAWEI Developers official website

>> Development Guide

>> Reddit to join developer discussions

>> GitHub or Gitee to download the demo and sample code

>> Stack Overflow to solve integration problems

>> Original Source

Follow our official account for the latest HMS Core-related news and updates.

--

--

Manoj Kumar
Manoj Kumar

Responses (1)