Scanning and converting old black and white film negatives to color images using DeepAI
This post is unrelated to my previous posts about (bio)medicine, but uses some of the Python skills that I learned during my PhD research. It doesn’t go into any detail on the theory behind deep learning, instead it shows a practical example of how the technology can be used. I use Adobe Photoshop and Lightroom in this tutorial, if you succesfully used an open source alternative, let me know in the comments.

Lockdown again in large parts of the world and many people are again at home. If you’re looking for something to do that doesn’t involve any other people, you might find some inspiration in this tutorial.

My grandparents gave me soms old black and white negatives and this blog post describes my process of scanning, digitizing and colorizing them with DeepAI:

after vs before

Scanning film negatives

I scanned the film negatives with my DSLR (Nikon D3500 and Samyang 135 mm f/2.0 lens), a tripod, my phone as a backlight and a cardboard box that I cut out so the negative could fit in. If you don’t have a DSLR, you could use your phone as camera and laptop screen as backlight but don’t expect amazing results (use an app that captures RAW files and ideally a tripod to keep the ISO as low as possible. I have added a comparison below of DSLR vs camera of the Xiaomi Mi 9T).

DIY negative scanner, smartphone stands against the back of the box. There needs to be some distance between the film and the smartphone, or else you end up with the pixel pattern in the image.

My camera settings were ISO100, f/4 and 1/8 sec shutter speed (make sure that you shoot in RAW instead of JPG), which results in an image like this:

Inverting the negative images

Every photo is different, so you’ll have to experiment with what works. I started off with the guide of Alex Burke (B&W negatives are a bit easier than color negatives).

scanned, cropped and edited B&W

The lightroom preset can be found on my Github.

Colorizing the B&W image

Now we get to the most interesting part: using deep learning to convert the B&W image to a colorized image.

There are many options available on the internet, but most either cost money or just aren’t that good (or both). I started off with the “Colorize” function of the new Neural Filters on Photoshop, but the result was terrible.

After some more googling, I found DeepAI. Unfortunately, every image larger than 1200x1200 pixels gets downscaled, which is a shame if you use RAW files and high resolution images in the rest of your workflow. As far as I know, the paid version of deepAI also doesn’t support larger images, if they do please let me know.

Fortunately, DeepAI allows the submission of jobs with an API. In other words, if we split our image in overlapping tiles of 1200x1200 pixels, colorize the tiles, and afterwards stitch them together, there shouldn’t be any quality loss. Splitting the image can be done with this code:

Once all images are splitted, we can use Python to submit every individual tile to DeepAI:

Merging the individual frames automatically in Photoshop: File > Automate > Photomerge and performing some additional tweaks (contrast, vibrance, …) depending on the image:

With my smartphone instead of my DSLR yield substantially worse results, but I haven’t optimized this process:

All code is available on my GitHub. If you find any bias in the models used by DeepAI, please let them know by sending a tweet or an e-mail.

Have fun, stay at home, social distance and stop the spread of the coronavirus.
['Ruben Van Paemel']
['Python', 'Artificial Intelligence', 'Photography', 'Opencv', 'Deep Learning']