Undo the Edits

Playing with Image-Editing Code

At AS-Level, I took Photography as a subject in my Sixth Form. It was the first time I really learnt about different features of Adobe Photoshop. In a classroom again, I found myself thinking about Photoshop. It was in one of my Machine Learning classes as part of my Master’s degree. The lesson covered algorithms to edit images. Initially, I found the lesson difficult. After taking some of my lecturer’s time afterwards to ask a few questions, I remember facetiously blurting out “I now appreciate Photoshop more!”.

After successfully creating image-editing code as assignments for that class, I decided to revisit some of my code after my degree. I wanted to see if I could undo edits I made in Photoshop with that code.

1. Inverted Images

My main script then included the many different methods from this file ready to be applied to an imported image:

(Using some of my brother’s photography,) I tested the invert method:

Using Adobe Photoshop Express to invert an image
Successfully obtaining the original image via the invert method

2.a. Halftone Images — Preparation

  • Applying a specified convolution filter
  • Applying a mean filter
  • Applying a median filter

(Again, RGB images were initially not considered so there were some tweaks to my original code for this.)

Applying a filter meant applying a set of values to an image. Technically speaking, an image would be represented as a 2D array. A filter would be a smaller 2D array to be overlapped and moved around the larger 2D array (the image). Matrix-calculations would be included to change the image’s 2D array values using the filter’s 2D array values. This would then produce a new 2D array: a filtered image.

A specified filter therefore meant the filter’s values were supplied. This is compared to the mean and median filters where the mean and median values (respectively) of the image itself were used as the filter.

Returning to my main script, some specified filters I included were as follows:

  • Laplacian filter (also known as an edge-detection filter)
  • Sharpen filter
  • Gaussian 3x3 blur
  • Gaussian 5x5 blur

To read more about this process and the specified filters, see here.

2.b. Halftone Images — Execution

I initially tested a Gaussian 3x3 blur on a 50% colour halftone image. There was no noticeable difference. The ~2000x1300 sized image meant my code to apply a filter took a few minutes. This coupled with the relatively small filter (3x3 compared to ~2000x1300) meant I changed the original image to ~500x300 to test more filters in a shorter amount of time:

(Please note blurry images will appear in succession of one another)

Applying the 50% colour halftone to a ~500x300 image
Gaussian 3x3 blur applied; Can notice the blur but the circles remained prominent
Gaussian 5x5 blur applied; It only appeared more blurry to me

After testing the Gaussian filters, I then tested the mean and median filters:

Mean 3x3 filter applied
Mean 5x5 filter applied; Despite appearing the blurriest, I noticed the halftone-dots the least here!
Median 3x3 filter applied; I believed the mean filter was still the front-runner
Median 5x5 filter applied; The presence of dots lessened but details appeared lost

After being the most satisfied with the Mean 5x5 filter, I then applied this filter to the image in its original size at halftone 50% and 25%:

The image with its original dimensions at halftone 50%
Mean 5x5 filter applied to the 50% halftone image
The image with its original dimensions at halftone 25%
Mean 5x5 filter applied to the 25% halftone image

After the many filters, I concluded the Mean 5x5 filter reverted the halftone effect the best. It would not produce a near-perfect result similar to reverting an inverted image. However, I believed I noticed the dots (introduced by the halftone effect) the least with this filter.

3. Pixelated Images

A pixel value of 20 produced loss of facial features in a 1200x800 image

After the success of the Mean 5x5 filter, I finished off my experiment by testing the pixelated images with this filter:

Image with pixel value = 6
Image with pixel value = 6 and Mean 5x5 filter applied; The face in the background appeared sharper but pixelation was still evident for the person in the forefront of the photo
Image with pixel value = 10
Image with pixel value = 10 and Mean 5x5 filter applied; Some smoothening of both faces occurred but pixelation is still prominent

Closing Remarks

Also, I now give more thought to the labour that has gone into filters via apps…

Thanks for reading!

Photo Credits

PS. Bloopers

Halftone 50%, Gaussian 5x5 followed by the Sharpen filter
Pixel value = 6 and the Sharpen filter applied