Image Filter App


Project codes are available at Github

The image filter app is developed with Python Imaging Library (PIL/Pillow), OpenCV and tkinter. PIL is a library for opening, manipulating, and saving many different image file formats. In this program, PIL is used to convert the image loaded with OpenCV (BGR color scheme) into a format compatible with tkinter's canvas (RGB color scheme). It is also used to resize and display images on the canvas. OpenCV is a library of programming functions for computer vision. It is used for image processing tasks like reading, writing, manipulating images, and applying various filters and transformations. Finally, tkinter is a Python Graphical User Interface (GUI) library used to create the GUI for the image filter application. It creates the main window, buttons, and canvas for displaying images. In this app, users are able to load images from their device and apply different filters, in similar fashion to image filtering features found in social media apps.

There are 9 filters implemented in this app.

On launching the app, users load an image from their device. After that, they choose one of the effects listed above. Users can also reset the image back to original.

Sepia and black and white

Sepia produces a reddish-brown effect, similar to photographs of the 19th and early 20th centuries. This is achieved by using a transforming the image with a matrix kernel of constant values. The black-and-white filter produces what its name suggests, black-and-white photographs. The filter first converts a color image to grayscale and then converting it back to RGB format for display.

plane1
Original
plane2
Sepia
plane3
Black-and-white

Brighten and emboss

The brighten effect brightens the image. It is achieved by multiplying the floating point representation of the image with a constant. The emboss effect adds rounded edges and shadows to create a 3D-effect.The effect is achieved by convolving the original image with a kernel matrix. The kernel matrix defines the weights that are multiplied with the pixel values to produce the embossed effect. The invert filter works by converting each pixel's intensity value to its complementary value. This done by subtracting the pixel value from the maximum intensity value of 255 for 8-bit images.

plane1
Original
plane2
Brighten
plane3
Emboss
plane2
Invert

Pixelate and oil paint

The pixelate effect pixelates the image by resizing it to a smaller size, then resizing it back to the original size. The smaller image will have fewer pixels, resulting in a lower resolution and a pixelated appearance. The resizing back to the original size causes the pixels in the smaller image to be scaled up, creating a pixelated effect from interpolation. The oil paint effect simulates the appearance of an oil painting by reducing the detail and complexity within localised regions of the image, creating a painted effect.

plane1
Original
plane2
Pixelate
plane3
Oil paint

Ink and blur

The filter works by enhancing and emphasising the edges in the original image, giving it a stylised appearance similar to an ink drawing. The blur function works by applying cv2's blur function. It uses an averaging filter which replaces each pixel's value with the average value of its neighboring pixels, effectively smoothing out the image and reducing noise.

plane1
Original
plane2
Ink
plane3
Blur

I created this image filter app because I wanted to know the approach behind implementing these filters. Besides the mathematics of changing pixel values using operations with matrices, the use of existing imaging and computer vision libraries come into play. In fact, social media apps have developed even more advanced filters that incorporate augmented reality, which involves a different stack of technology.