Fractals Revisited
Friday, 9th of October, 2015
When I was given my first computer nearly 30 years ago fractals were the newest and coolest thing around, they began to appear everywhere and everyone was making them or at least wanted to make them. Currently they seem to have fallen out of fashion and are considered passé except amongst nerdy people like myself.
After a couple of years of seeing fractals everywhere, I noticed that they appeared in many configurations, sometimes as just the fractals themsleves, other times as images of fractals appearing inside other images and quite often as textures applied to 3d objects, but I never saw non-fractal images appearing inside the fractals. I began to wonder if it would be possible to generate a such a fractal, where the colours were created by the colours of the embedded image instead of the usual simple colouring rules normally used to create them.
I eventually worked out how to do this by using 2 colouring rules, the first being a version of angular decomposition which I hijacked for this purpose and another one which I worked out for myself. An example of this can be seen below in an image I created in 1999 (featuring yours truly)-
The original images were created with the only programming language available to me at the time – a form of BASIC which could be compiled into stand-alone programs. Unfortunately it had severe limitations, such at the amount of memory available and the size and type of images which could be accessed and loaded into memory. To create images which were larger than 320×200 pixels or which required more than 256 colours I was forced to write files directly to the hard drive and needed graphic software which could read in raw data and convert it to something usable. If you look at the image above and pay close attention to the larger images at the periphery you may notice that they appear to be slightly “blocky” and this is due to the fact that the source image used was only 120×90 pixels in size.
When I decided to have another go at creating these fractals with embedded images I discovered that my BASIC software and all of the programs I had written were long gone, lost in the mists of time and dysfunctional back-ups, and I had forgotten how I did them the first time, so I had to work out how to do it all again from scratch. For my new creations I decided to use PHP and the GD library as I already had a small amount of experience creating images with them and this combination has the added benefit that images can be viewed in the browser as soon as they have been generated.
If you look again at the image above you will see there is quite a lot of distortion and all my original attempts to remove it were unsuccessful, so I decided to begin my new coding experiments by creating a test card which I could use to see exactly how the images were being distorted and also as a means of seeing if my attempts to remove or reduce the distortion were successful. In order to save myself time I generated the test card directly with PHP instead of using graphics software.
The first picture-in-a-fractal I created with the PHP and the GD library, although very pretty in its own right, shows just how severe the distortion really is:
I tried many different ways of removing the distortion, all of which involved mathematical processes to add an inverse amount of distortion and after many attempts this was the best reduction I was able to achieve:
Considering the fact that the processes I used to get this far were arrived at entirely by guess work it doesn't look too bad. I had a go at rendering an image with a photograph of myself in place of the test card to see how good or bad it looked. However, as can be seen from the image below it was painfully apparent that the level of distortion was still unacceptably high and even more correction would be necessary to remove it.
The problem lay in the fact that the initial distortion appearing in the remapped images was not happening in a uniform or predictable way and therefore was impossible to remove with simple mathematically induced corrections. I decided upon a different approach - I would attempt to actually measure the distortion and use that measurement to undistort the embedded images. To do this I needed to find an image “cell” which was reasonably regular in shape and below is a magnified version of the one I chose in which the radial lines (running from the centre of the fractal outwards) are almost parallel and the centre line is reasonably straight.
It turns out that measuring the distortion is a particularly slow process but which yields very good results, as can be seen here in the corrected version of the embedded test card image:
OK, so there was still some distortion but this was bound to happen anyway and it was at a level I could live with, so I tried generating a fractal with my photo in place of the test card and this is how it came out:
Comparing it to the original you can clearly see the improvements:
The anti-distortion works for Julia sets too: