Logo by Trifox - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

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: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. March 29, 2024, 04:53:28 PM


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
  Print  
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 2536 times)
Description: How do I solve color bands with histogram coloring?
0 Members and 1 Guest are viewing this topic.
CalvinCreator
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:
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!


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

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

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



« Reply #1 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/
Logged
CalvinCreator
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.

*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;
« Last Edit: March 13, 2017, 01:13:45 AM by CalvinCreator » Logged
CalvinCreator
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.
Logged
claude
Fractal Bachius
*
Posts: 563



WWW
« 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>.
Logged
CalvinCreator
Forums Newbie
*
Posts: 9


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

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

Related Topics
Subject Started by Replies Views Last post
Histogram jitter test 1 FractalWorks Gallery Duncan C 0 1820 Last post December 20, 2008, 03:57:59 AM
by Duncan C
Histogram jitter test 2 FractalWorks Gallery Duncan C 0 1505 Last post December 20, 2008, 03:58:00 AM
by Duncan C
Histogram Coloring Issue Programming clonexpert 9 3817 Last post February 21, 2010, 04:29:28 AM
by Duncan C
histogram colouring is really streching (not true histogram) Kalles Fraktaler claude 3 10861 Last post December 14, 2014, 11:34:00 PM
by claude
Ray Histogram Fusion Fragmentarium 3dickulus 12 2352 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.549 seconds with 27 queries. (Pretty URLs adds 0.043s, 2q)