Logo by Fractal Ken - Contribute your own Logo!


it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit us on facebook
Welcome, Guest. Please login or register. September 24, 2020, 07:11:43 AM

Login with username, password and session length

The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!

Pages: [1]   Go Down
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Smooth Histogram Rendering  (Read 1098 times)
Description: How do I solve color bands with histogram coloring?
0 Members and 1 Guest are viewing this topic.
Forums Newbie
Posts: 9

« 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:
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:

This is all using this color palate:

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:
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(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!

* Example 1.png (98.79 KB, 801x745 - viewed 125 times.)

* Example 2.png (117.96 KB, 799x703 - viewed 122 times.)

* palate.png (0.69 KB, 201x49 - viewed 382 times.)
Fractal Molossus
Posts: 652

« Reply #1 on: March 13, 2017, 12:22:19 AM »

However, with what I have currently there are color bands instead of smooth gradients.

Forums Newbie
Posts: 9

« Reply #2 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.

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;
« Last Edit: March 13, 2017, 01:13:45 AM by CalvinCreator » Logged
Forums Newbie
Posts: 9

« Reply #3 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.
Fractal Bachius
Posts: 563

« Reply #4 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>.
Forums Newbie
Posts: 9

« Reply #5 on: March 13, 2017, 03:53:03 AM »

That worked perfectly claude! Thank you very much!
Pages: [1]   Go Down
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Histogram Coloring Issue Programming clonexpert 9 2677 Last post February 21, 2010, 04:29:28 AM
by Duncan C
Histogram/Sort equalization Help & Support SeryZone 13 436 Last post May 05, 2014, 07:02:31 PM
by SeryZone
Histogram equalization tests Images Showcase (Rate My Fractal) SeryZone 0 439 Last post May 02, 2014, 07:58:02 PM
by SeryZone
histogram colouring is really streching (not true histogram) Kalles Fraktaler claude 3 2312 Last post December 14, 2014, 11:34:00 PM
by claude
Ray Histogram Fusion Fragmentarium 3dickulus 12 1616 Last post October 09, 2015, 03:01:41 PM
by 3dickulus

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.146 seconds with 27 queries. (Pretty URLs adds 0.007s, 2q)