Introduction:

“Black and white to color. It’s that simple.”

Coloring old photos is a time – consuming effort.

Coloring old photos is also an art, restoring history.

When it comes to coloring old photos, the first thing that comes to mind is an artist named Marina Amaral. She has filled in many famous old photos in the history with colors through post-processing.

It’s real, it’s realistic, you can’t see a flaw in it, and how much you admire her work is a sign of how complicated the craft is.

So,Do you want to learn how to color in old photos?Or photos of my parents, or childhood photosBlack and white photos turn to color?

Then mumuko’s advice to you is: don’t bother, because, this job, it can be left to the AI.

Today we will teach you to make an old photo repair tutorial – black and white photo coloring tips!

The body of the

** Baidu AI open platform “black and white image color”, ** this strongly recommended, 20 lines of code can handle black and white photos to color!

The first step: search Baidu AI into the official website to find: open ability — “image technology.

Step 2: Find the black and white image to color.

Step 3: You need to register as a Baidu developer, create an application, obtain API Key and Secret Key, and then obtain access_token. Input black and white image to obtain Base64 encoding of color image. Then turn the Base64 encoded string into a picture!

The attached code:

Import base64 import requests # client_id Client_secret is SK host = obtained on the official website 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id= AK&client _secret = you SK' response = requests.get(host) if response: Print (response. Json ()) # # black and white image color request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/colourize" F = open('test.png', 'rb') img = base64.b64encode(f.read()) params = {"image":img} access_token = response.json()['access_token'] request_url  = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, headers=headers) if response: Img = base64.b64decode(response.json()['image']) file = open('result.jpg', 'wb') file.write(img) file.close()Copy the code

The effect is as follows —

The first group of old black and white photos:

The second group of black and white old photos —

The third group of black and white old photos —

conclusion

The last one is amazing. Is it beautiful to you? Whachakka, why don’t you take the code and try out the coloring effect yourself?

Free source code collection:

For complete project source code + source material base see: # private letter xiaobian 06# or click on the blue text to add you can get free benefits!

Your support is my biggest motivation!! Mua welcomes you to read the previous article