Python and OpenCV Photo Filter

Many software tools are out there to edit and add effects to photos. The most common being Adobe Photoshop where one can easily add filters and customize details to alter the image or even add to it. 


I wanted to see if I could automate certain tasks that would be done in photoshop, into a python script.

Not only that, my goal is to create instead of black and white images, black and green images only, duotone. 


Why? I have an unhealthy obsession with green and black themed screens and work environments. Something about the old feel and look of terminal screens from the 80’s I think is too cool and I like people thinking I'm working in the matrix when I'm really just scrolling through linux directories. 


To do this I used opencv: A Python library used for computer vision, specifically I'm going to use it to read in image data of the pixels and their colors. 


This article here gives a great tutorial on how to convert an image to black and white, grayscale. 


Next, I applied masks to convert each pixel on the grayscale from gray to green and matched the intensity of gray to the intensity of green for each pixel scanned, so it copies and reflects the same shading as the original image.


Lastly, I edited a .png image to be transparent then used the pillow library to add my “watermark” to each image which I ran my filter on. A tutorial of how to add your image to another using python is here: 


Now when we bring it all together: 


the original image:

After running’s filter:

Very dystopian and toxic-looking scene... HOW FUN!!

Thanks for reading  

- Dom

April 7, 2021, 8:30 p.m.