A method of removing JPEG artefacts from old screenshots

Anything else unrelated to gaming can go here.
Post Reply
User avatar
MrFlibble
Demoniac Demo maniac
Demoniac Demo maniac
Posts: 3730
Joined: Sun Dec 05, 2010 11:39 am

A method of removing JPEG artefacts from old screenshots

Post by MrFlibble »

JPEG compression has ruined many an old screenshot in the 90s, but there's a way to somewhat reduce the damage.

For example, here's a screenshot from Tyrian that comes from the Epic MegaGames website (magnified at 2x using nearest neighbour interpolation for better viewing):
Image

There's quite noticeable tiling, overall blurriness and distortions around the edges known as mosquito noise. I've been trying to figure out a way to reduce these kinds of artefacts, and came up with the following method using GIMP. The result is shown below:
Image

The much cleaner image is accomplished by the following steps:

1. Import the source image into GIMP. Personally I prefer to first convert it from JPEG to a lossless format prior to importing but I think it doesn't actually make any difference.

2. Scale the image to 400% of its original size (which is 1280x800 in the case of a 320x200 image) setting interpolation to None (other software may call this the nearest neighbour interpolation).

3. Apply Median filter at the redius of 2. To do this, go Filters -> Enhance - > Despeckle, in the dialog box uncheck Adaptive and Recursive (if checked), set Radius to 2, Black level to -1 and White level to 256. In Photoshop, just use the Median filter with the same radius. This will reduce some of the mosquito noise.

4. Apply selective Gaussian blur (Filters -> Blur -> Selective Gaussian Blur). The Radius and Threshold levels might need to be adjusted for each image individually to achieve adequate mosquito noise removal. For the image above, I used Radius 10 and Threshold 20.

5. Apply the Pixelise filter (Filters -> Blur -> Pixelise) with pixel width and height both set to 4. This will effectively revert the image to its state when it was scaled up from the original size at 400% with the nearest neighbour interpolation.

6. Apply the sharpen filter at a high level of sharpness. I used 50 in this example. This is optional but will help make the resulting image more crisp by offsetting the effects of the blur filter used above.

7. Scale the image down to its original size. The Sinc3 (Lanczos) interpolation method seems to produce good results here.

Note that wile this method reduces visible mosquito noise, it does not address other distortions resulting from JPEG compression, such as discolouration, colour distortion, blurring and loss of image detail due to the former. Also areas with low contrast between neighbouring pixels get more blurry due to the selective Gaussian blur filter, which may result in some loss of detail. However overall the image is cleaned from the noticeable JPEG compression artefacts while preserving much of original detail.
User avatar
MrFlibble
Demoniac Demo maniac
Demoniac Demo maniac
Posts: 3730
Joined: Sun Dec 05, 2010 11:39 am

Post by MrFlibble »

I've also come up with a way to kinda-sorta improve image quality for screenshots mangled by GIF compression. Here's an example, one of the official screenshots for Crazy Drake (again, magnified by 2x with the nearest neighbour method):
Image

The GIF compression artefacts result in checkerboard-esque patterns of contrasted pixels due to dithering. I've tried to remove them or at least make them less pronounced, to the following result:
Image

It's not perfect but at least somewhat better. This was accomplished with the following steps:

1. Upscale the image 4x (1280x800 in this case) using nearest neighbour.

2. Run the Median filter at 2 pixel radius (see the first post above for how to do this in GIMP).

3. Run Selective Gaussian Blur at 5 pixel radius and a threshold of 100.

4. Scale the image down to original size using Bicubic interpolation.

Selective Gaussian blur with higher radius and/or threshold may or may not yield even better results.

UPD: Here's an alternate, simpler method that seems to be even better:
Image

1. Convert the image to PNG (24-bit colour), and use Selective Gaussian Blur without resizing it at the radius of 2 and threshold of 100.

2. Export the image as GIF.
User avatar
MrFlibble
Demoniac Demo maniac
Demoniac Demo maniac
Posts: 3730
Joined: Sun Dec 05, 2010 11:39 am

Post by MrFlibble »

Suddenly I realised that the waifu2x scaler algorithm can also do noise reduction, and gave it a try via this implementation. I think it does a pretty good job. Here's an official Duke3D screenie for example:
Image

And here's the result of waifu2x' noise reduction, using level 3 (because the original is that noisy)
Image

I think there's quite a noticeable improvement, and without much loss of actual image detail.

And here's what it does to an original Shadow Warrior shot (noise level 2):
Image

The result is clearly superior to what I got with my method described above:
Image

waifu2x got rid of the ringing and mosquito noise, and the text on the HUD is clearly readable. There's some minor detail loss but the gains of removing the noise outweigh that.

For another test, let's take a terribly noisy screenshot that was damaged by successive JPEG conversions:
Image

Now remove noise at level 3:
Image

Now that's pretty decent, don't you think? Not perfect, but quite better.
Post Reply