Logo by yv3 - 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: Did you know ? you can use LaTex inside Postings on fractalforums.com!
 
*
Welcome, Guest. Please login or register. March 29, 2024, 03:55:07 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] 2   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: Determining color  (Read 3306 times)
0 Members and 1 Guest are viewing this topic.
kronikel
Navigator
*****
Posts: 79



« on: November 21, 2010, 08:33:49 PM »

Could anyone give me a little example code for finding out what color to make a pixel after finding out its number of "iterations"?

I use
Code:
Color:= HSLToColor(Iterations * CAmount, 100, 50);
This produces a very "pure" color. Full saturation, medium brightness, and a hue based on the iteration.
The Iterations is of course the number of loops for the pixel.
The CAmount is the important part, and this is what will make the image look nice and clean or all pixelated.

Hue is anything from 0-100.
So my first thought was make it where CAmount was (100 / x) where x = the highest iteration found in the image.
This gives every iteration a different number, 0-100.
It works great for lower zooms but as you zoom in a bit there is a problem.
After some debugging I saw that when zoomed in a bit there is a massive difference between the "average iteration" found and the "max iteration" found.
The average might be only 35 while the highest one found could be something like 1000.
So assigning each iteration a hue from 0-100 won't fully work.

There is usually a certain CAmount that makes any rendering look nice and clean but I'm not quite seeing the pattern.
I would either like to figure this out or just find an easier way to assign a color.
« Last Edit: November 21, 2010, 08:36:25 PM by kronikel » Logged
jwm-art
Iterator
*
Posts: 171



WWW
« Reply #1 on: November 21, 2010, 10:06:41 PM »

An oft used method is to use the iteration count to look-up a colour in an array. If you have 256 colours in the array, then the modulus of the iteration count with 256 is used so that when the iteration count is above 256 the colours wrap around again. The colours you put in the array is up to you.
Logged
kronikel
Navigator
*****
Posts: 79



« Reply #2 on: November 22, 2010, 12:17:15 AM »

I see what you are saying but using HSLToColor works exactly the same.
For example if the outcome of (Iterations * CAmount) is 173, you would have
HSLToColor(173, 100, 50). It is above 100 so it automatically wraps around and makes the same color as HSLToColor(73, 100, 50)
So any number, even 20945820958 can be plugged into it.
Logged
jwm-art
Iterator
*
Posts: 171



WWW
« Reply #3 on: November 22, 2010, 12:45:57 AM »

I see what you are saying but using HSLToColor works exactly the same.
For example if the outcome of (Iterations * CAmount) is 173, you would have
HSLToColor(173, 100, 50). It is above 100 so it automatically wraps around and makes the same color as HSLToColor(73, 100, 50)
So any number, even 20945820958 can be plugged into it.

It doesn't work exactly the same because you're not calculating the colour you're translating the iteration count to an array index looking the colour up (ie fractint colour maps). You said the way you're using doesn't work for you and that the results are too saturated. Using a palette to look-up colours allows you to choose exactly the colours to use - and you don't need to worry about working out the minimum and maximum iterations for the image (unless you want to automatically scale the colour palette I guess).
« Last Edit: November 22, 2010, 12:49:28 AM by jwm-art » Logged
kronikel
Navigator
*****
Posts: 79



« Reply #4 on: November 22, 2010, 02:43:16 AM »

You're not understanding.
And my colors aren't too saturated, I'm not sure where you got that.
I know the problem but explaining it is hard so here is a picture.

If you look at all the iterations that were found for the whole image most of them would be around the same number, but as you get really close the the black area the iterations become very distant from the "average iteration" found.
If there were a decent way to just set the color of those pixels to the color of the highest iteration that was commonly found it would fix the problem.

Edit:
Ok making that picture into a .jpg actually made it look not half bad because it made it lose a lot of detail so it's not the best example.
But the closer you get to the black area the more pixelated it gets.


* fractal.jpg (37.19 KB, 295x295 - viewed 520 times.)
« Last Edit: November 22, 2010, 02:47:42 AM by kronikel » Logged
jwm-art
Iterator
*
Posts: 171



WWW
« Reply #5 on: November 22, 2010, 09:55:05 AM »

Ok I understand now. I think you will be wanting something called Oversampling sometimes also referred to as anti-aliasing. The basic principle is to render a higher resolution image and then down-sample it.

Take a look here:
http://www.fractalforums.com/programming/antialiasing-fractals-how-best-to-do-it/
Logged
kronikel
Navigator
*****
Posts: 79



« Reply #6 on: November 22, 2010, 07:18:28 PM »

Awesome, after putting "anti aliasing" into wikipedia sure enough I found some before and after pictures of fractals that had been anti alias'd.
The before looked exactly like my problem and the after looked nice.

Thanks for the help and everyone else who has helped me get as far as I have.
Logged
kronikel
Navigator
*****
Posts: 79



« Reply #7 on: November 22, 2010, 07:46:54 PM »

Ok what I found on that post has me completely confused now.
This looks like what I need though-
Quote
a very simple and effective way to antialias the heightmap is via supersampling: instead of just using 1 sample per heightmap value, divide each "region" of your M x N map into K x K subregions (effectively enlarging it by a factor of K in each dimension, but you don't store all those values) which you evaluate and average to produce your final heightmap value. this is a simple way to bandlimit your signal, discarding all high frequency data that cannot be represented at the current sampling frequency (i.e. above the nyquist limit).

Code:
for (y = 0; y < yres; ++y)
for (x = 0; x < xres; ++x)
{
float r = 0.0f, g = 0.0f, b = 0.0f;

for (v = 0; v < supersample_factor; ++v)
for (u = 0; u < supersample_factor; ++u)
{
float fx = float(x) + float(u) / float(supersample_factor);
float fy = float(y) + float(v) / float(supersample_factor);

colour eval = pixel_function(fx,fy);

r += eval.r;
g += eval.g;
b += eval.b;
}

r /= float(supersample_factor * supersample_factor);
g /= float(supersample_factor * supersample_factor);
b /= float(supersample_factor * supersample_factor);

imagedata[y * xres + x].set(r,g,b);
}

I don't understand how to implement this in my code at all.

Edit:
After some reading I still don't understand that code at all but I think I get SuperSampling.
You take the pixels that have the high iterations that are giving the image the "noise" and zoom in on those, calculate the colors that are around that pixel, then the color is an average of those colors.
That sounds extremely slow to me though unless I'm not thinking of it correctly.
« Last Edit: November 22, 2010, 07:55:09 PM by kronikel » Logged
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #8 on: November 22, 2010, 08:24:42 PM »

That sounds extremely slow to me though unless I'm not thinking of it correctly.

You're thinking correctly \o/
Supersampling is insanely slow  angry
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
kronikel
Navigator
*****
Posts: 79



« Reply #9 on: November 22, 2010, 08:44:24 PM »

So that's probably not the way I'm going o.O
My program is already slow.
Any ideas on anti aliasing anyone?
Logged
jwm-art
Iterator
*
Posts: 171



WWW
« Reply #10 on: November 22, 2010, 09:13:15 PM »

So that's probably not the way I'm going o.O
My program is already slow.
Any ideas on anti aliasing anyone?

Can you time your program so we have an idea of how slow 'slow' is? What language are you using, what hardware is it running on?

For example, how long does it take your program to render the default view of the Mandelbrot set?

Slowness is just something you have to put up with, with fractals unfortunately.
Logged
kronikel
Navigator
*****
Posts: 79



« Reply #11 on: November 22, 2010, 10:22:00 PM »

It is basically written in delphi but I use a compiler called scar to execute the code.
Scar is not meant for this being the reason it is slow.
Scar compiles code then runs it, which is a lot slower than something precompiled.
I did however make a plugin for the function that counts the iterations of a pixel, so when that function is called it is precompiled and executed in delphi rather than scar and saves a lot of time, but the whole code can't exactly be done like that.
I need to learn more c and I could easily have it running quickly.
The start view of the Mset only takes maybe 2 seconds to render.
Some deeper zooms might take 5-10 seconds.
I keep my render size at 100x100 though which is quite small.
500x500 takes forever.

Also I think anti aliasing might not be my answer.
I took a loot at the color mapping techniques by hpdz and that could work too.
Right now I'm trying to implement "Rank-order" mapping.
« Last Edit: November 22, 2010, 10:26:58 PM by kronikel » Logged
kronikel
Navigator
*****
Posts: 79



« Reply #12 on: November 23, 2010, 02:12:39 AM »

Now I'm trying "histogram" mapping
Can anyone elaborate on
Code:
J(x) = Sum[H(i), i=0 to x]
u = J(x) / NUM
The 2nd line makes sense.
For the first one I believe Sum adds together a part of an array of numbers.
And I'm really not sure what to do.
Logged
jwm-art
Iterator
*
Posts: 171



WWW
« Reply #13 on: November 23, 2010, 02:29:17 AM »

Now I'm trying "histogram" mapping
Can anyone elaborate on
Code:
J(x) = Sum[H(i), i=0 to x]
u = J(x) / NUM
The 2nd line makes sense.
For the first one I believe Sum adds together a part of an array of numbers.
And I'm really not sure what to do.

It looks like u is an average of all values in array H, ie NUM is the number of elements in array - at a vaguely informed guess!
Logged
kronikel
Navigator
*****
Posts: 79



« Reply #14 on: November 23, 2010, 02:42:23 AM »

It is from this article http://www.hpdz.net/TechInfo_Colorizing.htm#IndexDistribution
Where it tells about histogram mapping.
and NUM is "the total number of points in the image (outside the set)"
It doesn't give a lot of info really.
Logged
Pages: [1] 2   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Color bands Mandelbulb 3d bib 6 1562 Last post March 10, 2011, 10:23:13 PM
by marius
It's all about color Mandelbulb 3d chaos_crystal 4 1683 Last post March 07, 2011, 07:32:54 PM
by Madman
Fine tune color Mandelbulber scheven_architect 2 1780 Last post May 02, 2011, 11:40:47 AM
by taurus
Map for the diffuse color Mandelbulb 3d mario837 5 1883 Last post August 30, 2011, 09:05:32 PM
by kameelian
Color Box Gestaltlupe Gallery trafassel 0 1148 Last post October 02, 2011, 08:32:30 PM
by trafassel

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.299 seconds with 24 queries. (Pretty URLs adds 0.014s, 2q)