But what’s it for?

When I posted about my VHS and PAL plug-ins for The GIMP, I forgot to say why I originally wrote them. As I was using the VHS plug-in last night, I thought it might be interesting to explain what I was using it for.

I often find myself taking captions found on old multi-generation VHS tapes, and trying to recreate them in Inkscape (or, in the old days, in Macromedia Flash).

The trouble is that VHS changes can change the way captions appear. In particular, it changes the way the text on captions appears. This makes it very hard to match the typefaces used on captions with ones I have in TrueType, Postcript or OpenType format.

Take this caption, for example (click on it to make it bigger).

Could you help someone coping with franchise loss?

When I saw it, I knew immediately that the “PUBLIC SERVICE ANNOUNCEMENT” text was in Compacta Bold. However, when you create the caption in Inkscape it simply doesn’t look right (click on it to make it bigger).

Together we can beat pipe smoking.

As you can see, the text looks so much thicker it’s almost as if I’ve used the wrong font weight. But I know that the text is not Compacta Medium – that would be far too thin. And I also know there were no other weights of Compacta available to Scraggie and his friends in the Mecanorma or Letraset dry transfer lettering catalogues in the 1970s. So what’s going on?

If I load the Inkscape caption into The GIMP and put it through my VHS filter, which reproduces the mangling that VHS inflicts on television pictures, you get something that looks like this.

Dinage isn’t the problem it was.

The weight of the font in the caption above looks more like the original – and I’ve clearly used the right typeface all along.

The Southern Television logo is used courtesy of Nic Ayling.

And now for something completely different…

One of the things I spent a day doing at the end of September was add a few bells and whistles to the PAL and VHS plug-ins I wrote for the free software graphics program The GIMP.

I had found there were a few repetitive tasks I tended to do to images when I was making them look like PAL or VHS screen captures and thought I could automate these and include them in my plug-ins.

A major change to both plug-ins was that I made them scale any image fed into them to 720 x 576 (if they were not already that size). This was because the effects simply don’t look convincing on images much smaller or larger than actual television resolution.

The main change I made  to my PAL plug-in was to add an optional “interlace” effect.

The new PAL plug-in dialogue box

This is something that is designed to copy the rather stripey way PAL screen shots tend to look. There are many plug-ins that called “de-interlace” available to take the interlace effect out of images but I think this is the first one I’ve seen that actually puts the interlace in!

The interlace option creates a new layer above your image containing every other scan line from the original image. It then shifts the new layer slightly to the right and blurs it slightly with a light Gaussian Blur. Finally it merges the two layers together which creates the interlace effect.

Here’s a picture without interlacing:

Click to enlarge

And here’s the same picture with interlacing:

Click to enlarge

You’ll definitely need to enlarge the pictures to see the effect, as it’s quite subtle.

Another change I made was to add a PAL-S/PAL-D option. These are two different methods of encoding the colour in a PAL picture. PAL-D averages colours across adjacent scanlines in a field. I don’t simulate this properly yet, I simply halve the vertical resolution of the luminance which doesn’t work very well. If you’re interested, Alan Pemberton’s site has a wealth of information about PAL.

Here’s an image with PAL-S or simple PAL:

Click to enlarge

Here’s the same image, but with PAL-D selected:

Click to enlarge

As you can see from the results above, I need to do some major rework on the PAL-D feature, but I’ll save that for another day.

There were a few options I added to my VHS plug-in. The first, was to add an option to cut out the VHS picture area – this was because to save space the VHS format did record the whole of a 720 x 576 PAL image – scanlines which weren’t visible are not recorded. This is a real shame as, if VHS players did record all the image scanlines, Mike Brown would have an awful lot more vintage teletext on mb21.

You can see the picture area recorded on a VHS tape in a 720 x 576 PAL image below:

Click to enlarge

The next thing I added was a suggestion of Rory Clark. He suggested I simulate a “messy VHS head change”, which looks like a distorted area at the bottom of the picture area. You can see what a messy head change created by my VHS plug-in looks like below.

Click to enlarge

Rory also suggested that I might like to add a “glitch” that could appear horizontally across the picture at a particular point. This is what one looks like:

Click to enlarge

I added a slider so you can specify the Y position of the glitch.

The new VHS plug-in dialogue box

There are various other things to add to the plug-in such as comet tails, but I’m quite happy with how it’s coming along so far.

If you read the previous article you’ll already know that I’ve licensed my plug-ins under the GPL v3 and they can be downloaded, as usual, from here. Installing the plug-ins tends to be simplicity itself for most GNU/Linux users (simply copy it into your /home/.gimp2.6/plugins folder) but Windows users may need a bit of extra help.

I thought I’d also upload the plug-ins to the official GIMP plug-in registry so that anyone looking for a PAL or VHS plug-in there would be able to stumble across them. They’re stored here.

I was particularly pleased that a very helpful chap called “mahvin” who often frequents the registry found a bug in my PAL plug-in, and was even more pleased when he thanked me very nicely indeed for fixing it quickly. This was truly a double bonus as mahvin’s site contains his blog which is full of excellent tips on doing all manner of ingenious things in The GIMP and is well worth a read.

Obviously, each picture needs to be taken individually – these plug-ins are just a base to start from, but they have certainly given me a lot of fun, and I hope you’ll enjoy playing about with them too.

It may be rubbish, but at least it’s British rubbish…

My one stop shop for all your stupid rubbish download needs is now open here.

So now, for the first time everyone can:

And all in the comfort of your own home. How can you resist? I just hope Google’s servers are load balanced…

Filter tips (no Alistair)

I was bored of repeatedly applying my PAL and VHS effects to images by hand. It was a several stage process and rather fiddly: I desperately wanted to automate it. I knew it was possible to extend The GIMP by writing your own features in Python, so I decided to have a go and see how I got on.

The documentation for writing plug-ins in Python for The GIMP was pretty well hidden, but eventually I found it here. It was well written, very easy to follow, but it looked very old. For safety’s sake I felt I needed to have a hunt around and see if there were any more recent examples of filters for the GIMP in Python I could find just in case anything had changed. The tutorial seemed to have been written for The GIMP 1.5 but on my computer I’m currently using The GIMP 2.6.

Although I did try Google, the best example of Python filters for the latest version of Python were installed with The GIMP itself and sitting in:

/usr/lib/gimp/2.0/plug-ins

Sure enough, the filters in there that shipped with The GIMP 2.6 had a much better way of preserving The GIMP’s state before and after the filter is applied and help undo to work and also contained the gettext function that ensures your filter can be translated into other languages. There is also a slightly changed way of specifying which menu the plug-ins show up in in The GIMP.

Writing the plug-in itself was very easy indeed. No stretching, no unpleasant bending and the gedit text editor that comes with the GNOME desktop on Ubuntu GNU/Linux was all the equipment I needed.

Writing filter in gedit

I found using the Browse… button on the Python-Fu console in The GIMP was extremely handy. It brings up a Procedure Browser which I used for finding the functions I wanted to call and their syntax. It also showed me the constants I could use, which greatly reduced the number of “magic numbers” in my code.

Procedure Browser from Python-Fu console

The basic idea is that anything you can do in The GIMP with a mouse has a matching pdb (procedure database) function, so it’s really easy to write a macro-style filters – you just find the right function using Browse.. from the Python-Fu console and string them together. But as that because Python is a ridiculously easy language, it’s possible to do so much more than that. One thing I didn’t expect is that pdb functions sometimes have extra parameters that you can’t normally access using The GIMP itself.

The second part of your filter is a call to a function called “register” in which you specify the interface for your filter, its description and where you want it to appear in the application.

A filter’s interface is specified in its register function

The main problem I had was not writing the filters themselves but getting them to show up in The GIMP’s menu of filters. Firstly I needed to work out where to put the filters – with Ubuntu Linux the best place is in your home directory under .gimp-2.6/plug-ins.

But putting it in the right place wasn’t enough – there were two other issues. First, if you don’t set your Python scripts to “Allow executing file as program” they won’t show up in The GIMP. No warning, no nothing – if you forget to do that you just won’t see them.

Don’t forget to allow your filter to execute as a program

Secondly, you have to prefix your filter name with “python-fu-“, or again it will silently refuse to show up.

Once I did get the filter to appear and, better than that, it worked, it was an amazing feeling of achievement. It’s tremendously satisfying to customise a program to do some special things that you want it to do.

Success at last – click to enlarge

I’ve released both filters under the GPL v3, and they’re available to download from here.

Tapeheads Revisited

I was happily applying my “fake” VHS or fake PAL effects to a range of pictures thinking how clever I’d been when something started to bother me.

Most images looked fine, but some looked completely wrong. For instance, the “Colour Production” text on Yorkshire Television production captions looked awful. I needed to find out what was wrong.

It shouldn’t actually look this bad…

I went back to Alan Pemberton’s website and after reading this page again I realised what was wrong. A PAL colour picture is composed of a high definition black and white image (which contains the luminance or Y) and a low definition colour image (or chrominance). The luminance image and chrominance images are added together to make a colour image.

However, with the colour turned down, the luminance image looks like a normal black and white picture – complete with all the detail viewers in black and white would expect. Whereas my technique for faking PAL or VHS was chucking away far too much detail, and if I turned down the colour I would certainly not see an acceptable black and white image.

In particular, I was binning far to much information for red and blue, which was the reason that things like the blueish red “Colour Production” on the Yorkshire Television caption looked far to low resolution.

I could quite easily create a PAL luminance image, like this:

A PAL luminance image

And I tried to create a chrominance image, like this one:

PAL chrominance image, but you’ll have to imagine the negative colours…

However, when I tried to combine them, something was wrong.

Lightspots can be too light

The answer was that for my chrominance image to work, the PNG format would need to hold negative colour values. The chrominance image is what’s called a difference image and therefore contains negative as well as positive values. Alan Pemberton explains why this is much better than I could on his site.

So, I couldn’t be completely accurate in the way I created PAL images, but I thought I could do a better job than I had been. So I fired up The GIMP and came up with this.

I load my source image and create two layers. I call the bottom one Luminance, the other Chrominance. I make the Chrominance layer’s blend mode Addition.

For my Luminance layer I adjust the Red channel output level to 76, the Green channel output level to 150 and the Blue channel output level to 29.

Setting the Red channel level to 76

For the chrominance layer I adjust the Red channel output level to 179, the Green channel output level to 105 and the Blue channel output level to 226.

You may notice that each pair of numbers adds up to 255. The Luminance (Y) layer values were worked out using:

Y = 0.299R + 0.587G + 0.114B with R = G = B = 255

Then depending on what I am doing (PAL VHS or just PAL), I scale the Luminance and Chrominance layers horizontally and then scale them back to full size. For a nice PAL effect I found that scaling the Luminance layer by two thirds width and then back again and the Chrominance layer to a third width and back again gave a good effect.

For VHS I found scaling the Luminance layer by 32% and the Chrominance layer by 16% looked OK.

As a comparison, here’s a Yorkshire television caption done using the revised technique.

How We Used To Live – with lossy old VHS tapes

The next job is to turn my method into plug-in filters for The GIMP. Time to dig out my Python book!

Filthy tapes and dirty pictures

Recently I’ve been trying to work out how to recreate the PAL/VHS look in The GIMP. One article I read said that the colour (or chrominance, as they put it) signal on VHS recordings was very noisy. You can clearly see this on screen grabs taken from real VHS tapes.

The blotches here are due to genuine VHS/PAL chrominance noise

I tried to simulate this by adding RGB or HSV noise to the red, green and blue images I was creating. The results looked totally wrong. The trouble was that the noise was too even, with all the little blobs of noise being the same size. Click on the image below to enlarge it.

My unsuccessful attempt to simulate it using HSV noise

What I needed was some more realistic VHS noise, in which the blobs of noise were different sizes. Chrominance noise is rather like film grain in this respect, so after Googling “film grain gimp” I came up trumps with a very good article by Eric Kidd about film grain in The GIMP documentation which gave me the solution.

So, here is how I made my nice clean chrominance channels dirty:

  • I opened a real screen grab taken from a PAL VHS tape in The GIMP.
  • I duplicated the image onto a new layer so I had two layers in the same file containing the same image.
  • I blurred it the upper layer with Gaussian Blur until there was no noise visible.
  • I set the blend mode of the blurred layer to Grain Extract.
  • I flattened the image.

What you should end up with is an image that looks like this (click on it to enlarge it):

The grey areas are pure PAL/VHS chrominance noise

The grey areas contain the noise – which is what we are after. The next thing you need to do is choose a portion of the noise that looks best, and make it into a new image. After that you should make you noise image into a seemless tile the Make Seamless Map filter. This allows you to fill large areas with noise.

Here is the sample of real VHS noise I ended up with – it doesn’t look like much, but it works a treat!

This small PNG image was all I found that I needed

Now we can use the noise image to help us make a fake “PAL VHS” image. You apply it when you have scaled your red, green and blue images down to their “small” size – that’s before you restore them to 720 x 576 and composite them together.

First, I copied my noise image in The GIMP so it was on the clipboard. Then I used a Fill with the “Pattern Fill” fill type with “Clipboard” as the fill source. I also set the affected area to “Whole Selection” and the mode to “Grain Merge”. The bottom of your toolbox panel should look like this:

Here’s the recipe for those playing along at home

So all I am doing is blending my real VHS chrominance noise image over each of my colour channel images. Here’s my scaled green channel just after I applied the real chrominance noise.

The noise causes the slight blotchiness of the background

Here is an example of a finished “fake VHS” image with the real chrominance noise added (click to enlarge):

Very happy with the way this turned out

And here’s the Granada International example from earlier, but this time with real chrominance noise applied as a comparison (click to enlarge):

I think we just missed something dull and northern

That wraps it up for PAL and VHS – sorry I went on about it so much!

VHS Scale sizes

This is the list of scale sizes I use for scaling images to make “PAL VHS” screens in The GIMP:

            Broadcast    VHS (46.25% worse)
Y   0.299R  215 x 576        100 x 240
    0.587G  423 x 576        195 x 240
    0.114B   82 x 576         38 x 240

I tend to use non-square pixel 720 x 576 images as source material, or 788 x 576 source material that I scale back to 720 x 576.

Incidentally, the type of scaling you use is important. I nearly gave up on creating VHS style images at first because I was using Cubic interpolation when scaling in The GIMP. It gives very disappointing, blocky results (click to enlarge):

Cubic scaling gives a very pixellated look

However I soon worked out that, thanks to a bit of help from a clever Hungarian chap called Lanczos Kornél, I could use Sinc (Lanczos 3) interpolation when scaling.

Lánc, Lánc, eszterlánc…

That makes all the difference to the end results. Here is the same image created with Sinc Lanczos scaling:

Hungary restores Derek Batey’s honour

The sad thing is I probably spent more time on Border Television’s graphics than Border Television ever did when I was writing this post…

PAL VHS

After having a look at what PAL looked like on images that were broadcast to your television or arrived from a home computer, I wanted to have a look and see if I could simulate how a PAL VHS image would be mangled.

From what I could gather, a PAL VHS picture was 576 lines but it only stored a maximum horizontal resolution of around 333 pixels. On the back of an envelope I worked out that meant that the image stored on a VHS tape had about 46.25% of the horizontal resolution of a broadcast PAL image.

Therefore, suppose the original image was this Telefusion Yorkshire one (click to see it at full size):

Before: the original 720 x 576 pixel image

Then it would be stored as this much red information (click to see at full size):

Red – 100 x 576 pixels

This much green information (click to see at full size):

Green 195 x 576 pixels

and this much (or, rather, little) blue information (click to see at full size):

Blue 38 x 240 pixels

And when combined you’d get an image like this:

After: Simulated PAL VHS image

Incidentally, PAL images have non-square pixels. So in order to see the “before” and “after” images on this page in the correct aspect ratio I have scaled them horizontally from 720 pixels up to 788 pixels.