AP 186 Basic Image Operations
- Carl Naces
- Aug 29, 2018
- 2 min read
A PGM or portable gray map is one of the simplest image formats that can be used to study basic image operations. It can be imagined as an array of numbers that represents pixel values. Below are some PGM images that were created thru code in python, the jupyter notebook can be downloaded below.


On the left is a picture that has been converted to grayscale and then into PGM file format.
Since images are represented as matrices, constant values can be added to every one of these pixel values. Below we can see constant values of 20, 40, and 60 added to the gray image from above.

Following the same logic, constant values can also be multiplied to these pixel values.


The top two are synthetic PGM images of square and a flower and the bottom two are their image sum and difference. An important takeaway from this activity is that numpy arrays are of the data type uint8 which holds values from 0 to 255 but circles back to 0 if the pixel values exceed 255. In order to be able to perform these manipulations it is important to change the data type of your images to float or int.

Above is the histogram of the grayscale image of Momo from TWICE. You'll notice that there is a dominance with the pixels representing white values (values near 255). The values pointed by the arrow which are near 0 (near black) most probably are the pixels representing her hair.
For those who are interested in the python code you can access it here. Just replace the images with the images you like. https://github.com/5ever/AP186
For any questions, you can contact me through any of my contact details on the home page.
Comments