Processing images digitally with Python is not only a fun task, but it's also very easy to do.
In the following thread🧵, let me explain how you can do it from scratch using simple operations on a matrix.
1/7
First of all, as a context, PNG (Portable Network Graphics) images can naturally be represented by a 2D matrix of pixels.
At the same time, the pixels are made up of 3 RGB components, representing the colors Red, Green Blue.
2/7
Therefore, after converting a PNG image into a matrix, 2 operations that can be performed very easily are:
▪️Flip vertically: invert the order of the columns of the matrix
▪️Rotate 90 degrees: invert the rows by columns, traversing the matrix inversely
3/7
In addition, the illumination of the image can be modified:
▪️Apply brightness: add a constant value to all pixels of the image (e.g. alpha 0.1)
▪️Apply contrast: subtract a constant value to all pixels of the image
4/7
You can also calculate the negative of the image. To do this, subtract 1 from each color (maximum value for each component) and save the absolute value of this subtraction.
The image will look like this (very cool, right?):
5/7