Jump to content

User:Bensculfor/Plotting algorithms for the Mandelbrot set

From Wikipedia, the free encyclopedia


Histogram coloring

[edit]

A more complex coloring method involves using a histogram which pairs each pixel with said pixel's maximum iteration count before escape/bailout. This method will equally distribute colors to the same overall area, and, importantly, is independent of the maximum number of iterations chosen.[1]

The top row is a series of plots using the escape time algorithm for 10000, 1000 and 100 maximum iterations per pixel respectively. The bottom row uses the same maximum iteration values but utilizes the histogram coloring method. With the escape-time algorithm on its own, increasing the maximum number of iterations reduces the brightness of pixels that are far away from the boundary. Using the histogram method, these pixels retain their brightness at all iterations.

This algorithm has four passes. The first pass calculates the iteration counts associated with each pixel (but without any pixels being plotted). These are stored in an array, IterationCounts, where IterationCounts[x][y] is the number of iterations required to escape by the pixel at coordinates (x, y) on the screen.

The second pass creates the histogram of the number of pixels for each escape time value. This is stored in an array NumIterationsPerPixel, where NumIterationsPerPixel[i] is the number of pixels which require i iterations to escape (so the length of the array will be the maximum number of iterations). Pseudocode for this pass is:

for (x = 0; x < width; x++) do
    for (y = 0; y < height; y++) do
        i := IterationCounts[x][y]
        NumIterationsPerPixel[i]++

The third pass iterates through the NumIterationsPerPixel array and adds up all the stored values, saving them in total.

total: = 0
for (i = 0; i < max_iterations; i++) do
    total += NumIterationsPerPixel[i]

After this, the fourth pass begins and all the values in the IterationCounts array are indexed, and, for each iteration count i, associated with each pixel, the count is added to a global sum of all the iteration counts from 1 to i in the NumIterationsPerPixel array . This value is then normalized by dividing the sum by the total value computed earlier.

hue[][] := 0.0
for (x = 0; x < width; x++) do
    for (y = 0; y < height; y++) do
        iteration := IterationCounts[x][y]
        for (i = 0; i <= iteration; i++) do
            hue[x][y] += NumIterationsPerPixel[i] / total /* Must be floating-point division. */


Finally, the computed value is used, e.g. as an index to a color palette.

This method may be combined with the smooth coloring method below for more aesthetically pleasing images.

  1. ^ "Newbie: How to map colors in the Mandelbrot set?". www.fractalforums.com. May 2007. Archived from the original on 9 September 2022. Retrieved February 11, 2020.