The Artist's Husband: Smoothing a de Jong Image

/2020/10/the-artists-husband-smoothing-a-de-jong-attractor/images/deJongSmoothing.png

Last week , I showed a program I was working on to generate deJong attractor images. I mentioned I’d be working on adding some color. I am not there yet! This is a mere stop to take a breather, and to talk about an intermediate step: smoothing the image. Here is one of my images from last week:

/2020/10/the-artists-husband-smoothing-a-de-jong-attractor/images/deJongSmoothing_1.png

While interesting, there are some problems here. I am just calculating points, and as each one is calculated, I draw it on the canvas, even if it has already been drawn. For any given set of input constants, there are going to be the same points showing up a lot, some more than others. The final image, however, is very sensitive to the number of unique points I actually draw. Too few, and there is not much to see. Too many, and the image devolves into an amorphous blob:

/2020/10/the-artists-husband-smoothing-a-de-jong-attractor/images/deJongSmoothing_2_amorphous.png

So how can I draw some more detail out of this process? My approach was to, instead of drawing each point as I calculate it, keep track of the number of times each calculated point comes up. That’s potentially a lot of counters! An 800x800 image needs 640,000 of them. A 6000x6000 image needs 36,000,000! No matter! Keeping track of this kind of thing is what computers are for, as long as I don’t run out of memory… Once I have all the counts, I use them to generate the image. For each point on the canvas, I draw a pixel with a brightness based on the value. Higher values get brighter pixels. Now I don’t have to worry so much about drowning the image if I draw too many points, since calculating more points just tends to further improve detail. But where do I stop? Since I am generating a 16-bit greyscale image, I stop as soon as any point has been seen 65535 times. That is the largest value that will fit in a 16-bit integer.

This is what my image looks like now:

/2020/10/the-artists-husband-smoothing-a-de-jong-attractor/images/deJongSmoothing_3_final.png

I’d say that’s quite an improvement!

I don’t have any code to share this week. It’s in a state of flux as I work towards adding color to these images, and it’s getting a bit long and complicated to post. For those who are interested, I promise I’ll point to where to find the code at the end of this journey!