The maths behind Instagram's filters
With more than 2 billion active users globally, Instagram has become one of the world's leading platforms for digital communication and content generation.
Since its origins, the creative filters it offers to personalise images have been a distinctive element of the platform, contributing decisively to its visual identity and differentiating it from other social networks. Iconic filters such as Clarendon, Juno, Lark, Gingham or Ludwig have become part of the conversation.
But from a technological point of view, Instagram filters are much more than pure aesthetics: every time the Valencia filter is applied to an image, mathematical function transformations are being executed that alter pixel values following pre-designed curves.
Pixels and functions: the mathematical trick behind filters
To understand the science of an Instagram filter, one must first get to know its key players:pixels. A digital photo is made up of millions of tiny coloured dots called pixels, and each pixel is described by numbers. For example, in an RGB (red, green, blue) image, each pixel is actually a triplet of numbers indicating how much red, green and blue intensity it contains (in values ranging from 0 to 255). When you apply a filter, you are actually modifying these numbers using mathematical formulae.
In the same way that a recipe tells you how to transform different ingredients into a great dinner, a filter tells you how to transform the colours of an image into another style. Some recipes are simple: for example, increasing the brightness of a photo means taking each pixel and increasing its colour values to make everything look lighter (bringing them a little closer to 255, which would be white). Other recipes are more complex, such as changing the tone of the image to make it look like a warmer sunset: in that case the filter mightintensify the red componentof each pixel (e.g. by adding or multiplying by a factor) to create that reddish atmosphere.
Many filters uset one curves or LUTs (Look-Up Tables) to apply more elaborate transformations. Instead of simply "brightening up" or "lowering contrast" linearly, a tone curve is a graph that reflects the value of each colour after a filter.
For example, a filter may bet that originally dark pixels become much lighter, but those that were already bright hardly change at all, thus achieving more contrast. A LUT works like a table thattakes an input colour and converts it to an output colour. That is, the filter consults that table to "know" that, for example, a specific blue should become a greenish blue, or that a slightly pale skin tone should be transformed into a more tanned one. In this way, this colour mapping processassigns a new value to each pixel according to predefined rules, achieving effects such as dramatic contrasts, vintage colours or dreamy atmospheres consistently throughout the photo.
In short, altering pixels with mathematical functions means thatevery number in the image is modified according to a formula. This can be adding a fixed amount, multiplying by a percentage, applying a curved function (e.g. raising to a power to enhance halftones), or using reference tables filled with pre-calculated numbers.
The important thing is that behind every "brightness", "contrast" or "saturation" slider we use in the app, there are mathematical operations. Instagram's filters apply hundreds of these operations in milliseconds to each photo, adjusting each pixel to get the desired look.
But filters don't just change colours; many also add fun effects to a face: puppy dog ears and nose, flower crowns, virtual make-up, etc. For that effect to be placed in the right place, the software must firstrecognise a facein the image.
That is, it needs to detect where the face is and understand certain features of it. How does a mobile phone achieve something like this? The answer lies incomputer vision, an area of artificial intelligence that teaches machines to "see" images. How computer vision algorithms work, and the role they play in apps like Instagram, will be discussed in the next article.
Read more about
TikTok, Artificial Intelligence and mathematical probability
5 reasons why you should study mathematics applied to software engineering.
The perfect tandem for your future: mathematics and software engineering.
