Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: CalvinCreator on March 12, 2017, 05:35:15 PM




Title: Smooth Histogram Rendering
Post by: CalvinCreator on March 12, 2017, 05:35:15 PM
I've been playing around with fractals for a short period of time now, and have been trying to implement a histogram coloring method for rendering the Mandelbrot set. However, with what I have currently there are color bands instead of smooth gradients. Furthermore, the colors for the highest iteration levels don't always show up.

Example image:
http://imgur.com/Y491nZu
I don't know how to imbed the image in this post, so this is the best I could do. Alternatively, the images are all attachments below the post and are listed in the order mentioned.

When, if I zoom in a little more, this is what I see:
http://imgur.com/a/Wk7IY

This is all using this color palate:
http://imgur.com/a/bFV3c

As I loop through and calculate z values, I update an array at an index corresponding to how many iterations it took to escape minus one, with indices ranging from 0 to maxIterations - 1. I also mark in a  2D array, corresponding to each pixel on screen, how many iterations it took to escape to store for later.

Afterwards, I loop back through each pixel again and execute this code:
Code:
float hue = 0.0f;
int sum = 0;
for(int l = 0; l < iterationGrid[i][k]; l++)
sum += histogram[l];

hue = (float)sum / total;
if(iterationGrid[i][k] == maxIterations)
g.setColor(Color.BLACK);
else
g.setColor(palate[(int)(hue * 254)]);

g.fillRect(i, k, 1, 1);

For pixel at i,k where g is a Graphics2D object in java that lets me draw on the window, iterationGrid is that 2D array storing iteration values I mentioned, and total is my total amount of pixels, and hence the sum of my histogram. Palate is an array of Color objects with a length of 255.

Thank you very much!


Title: Re: Smooth Histogram Rendering
Post by: quaz0r on March 13, 2017, 12:22:19 AM
Quote
However, with what I have currently there are color bands instead of smooth gradients.

http://www.fractalforums.com/programming/please-explain-smooth-coloring/


Title: Re: Smooth Histogram Rendering
Post by: CalvinCreator on March 13, 2017, 12:47:03 AM
I have looked at this post while implementing the smooth iteration coloring algorithm. I implemented it (flawed perhaps? I got recurring bands of my color palate).

How do I mix smooth iteration coloring with histogram coloring? Both result in a floating point value for hue, but with one I get smooth, recurring bands of my palate and with the other I get a mostly evenly distributed color palate but without the smoothing.

*EDIT*
Should probably mention, when I do the smooth iteration coloring algorithm, I don't get a value between 0 and 1. Instead, I take the decimal portion of the value calculated and use that. The algorithm I'm using:
n = iterations + 1 - log(0.5 log ( z^2) ) / log(2);
n = n % 1;


Title: Re: Smooth Histogram Rendering
Post by: CalvinCreator on March 13, 2017, 01:26:19 AM
So I have been playing around a little bit and have fixed it so that there isn't that variance in what colors are displayed anymore. The issue was that the colors at maxIterations were being counted towards the histogram, the total, and other calculations. Hence, because the histogram is supposed to ensure that colors are distributed evenly, it didn't draw the yellows because it was already drawing other colors (black) in the same range. I just fixed it so that if iteration == maxIterations, it doesn't care about it.

The color bands still exist though, and that is more troublesome.


Title: Re: Smooth Histogram Rendering
Post by: claude on March 13, 2017, 01:40:59 AM
How do I mix smooth iteration coloring with histogram coloring?

I do it by sorting a copy of the smooth image iteration values, then looking up the index of each pixel (scaled by total count), to get a value between 0 and 1.  You can do various fiddling to stop unescaped pixels affecting the results.

If you're using C, then the standard library qsort() and bsearch() will do what you want, in <stdlib.h>.


Title: Re: Smooth Histogram Rendering
Post by: CalvinCreator on March 13, 2017, 03:53:03 AM
That worked perfectly claude! Thank you very much!