Previous Next

Merici - Ursula Hall Academic Journal: Volume 2, 2016

My lecturer’s cup

Lalit Prasad

Our first assignment in COMP2300 (Introduction to Computer Systems) instructed us to write a simple image filter in C, which would take in a user-provided image and input parameters and create a new image file with the desired filters added. It was compulsory to implement a black-and-white filter, and we were allowed to add as many other filters as we liked. I chose to add filters to change the image brightness and contrast, as well as a fun filter to produce a photo-negative.

Our assignment dealt with bitmap files, which primarily consist of a list of pixels with values indicating the brightness of red, green and blue within each pixel (ranging from 0 to 255). The standard approach to the problem was to first read the file to obtain the values of each pixel, then change the values as required, before finally writing these values to a new .bmp file.

Note that this becomes a little less straightforward when changing the dimensions of the image, for instance by cropping or rotating, as you cannot write the pixels to the output in the same order as in the original image. Indeed, after some thought as to how one might go about implementing such a filter, I decided that it was best left to the professionals and/or students with higher standards.

Most of the filters that I implemented were trivial, at least logically. For instance, my photo-negative filter simply inverted the colour of each pixel by subtracting each colour value from 255. To change the brightness, I multiplied each colour value by a non-negative ratio provided by the user (of course capping the maximum possible value at 255). In a similar vein, my black-and-white filter set each pixel’s colours to either (0,0,0) or (255,255,255), depending on its initial brightness.

The contrast filter was more difficult, as the changes to each pixel depended on the values of the other pixels in the image as well. Here, I first found the average brightness of the surrounding pixels, and then scaled each pixel’s brightness away from that average to the extent supplied by the user, heightening the contrast of the image.

Overall, my submission for the assignment was not very ambitious as I shied away from the more complicated extensions, but my code was quite clean (take my word for it) and I am quite proud of the contrast filter in particular.

No filter

Photonegative

Half brightness

Contrast doubled

Black and white


Previous Next