I am rendering a mandelbrot set and have already achieved somewhat smooth coloring, but when looking closer the picture becomes very noisy. I am wondering, what would be the best way to improve my coloring to achieve better aesthetics. Would using histogram coloring help remove the rough pixelated areas? Here is a render of the fractal using 10 000 iterations.
This is the way I'm generating and assigning colors right now:
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int black = 0;
int[] colors = new int[max]; //max is the maximum number of iterations
for (int i = 0; i<max; i++) {
colors[i] = Color.HSBtoRGB(i/256f, 1, i/(i+8f));
}
for(int i = 0; i < colors.length / 2; i++)
{
int temp = colors[i];
colors[i] = colors[colors.length - i - 1];
colors[colors.length - i - 1] = temp;
}
...
...
...
if (iterations < max) image.setRGB(col, row, colors[iterations]);
else image.setRGB(col, row, black);
}
}
//ImageIO.write(image, "png", new File("mandelbrot_seeria90"+Integer.toString(i)+".png"));
ImageIO.write(image, "png", new File("resotest.png"));
A simple solution that may produce acceptable results is simply to anti-alias using 2x2, 3x3 or 4x4 super sampling, and generate each pixel by averaging the color values (not the iteration count) of a block of 4, 9 or 16 pixels.
This approach is just a general image rendering technique, it's not using any specific knowledge of Mandelbrot fractals to the problem, but you could optimize it by calculating the iteration count for neighbouring whole pixels and only doing the sub-sampling step if the counts are not all the same. This means that you'll only be doing it where it counts: at the boundary between 2 iteration counts or in noisy areas with lots of different counts next to each other.
You can test this by generating a test image and then shrinking it down by a scale factor in an image editing application (make sure you have filtering turned on). If it looks ok then you can implement it by adding an extra couple of for loops inside your existing inner pixel loop, for each sub-pixel, incrementing c by 1/2, 1/3 or 1/4 of the pixel step. Add up the color values and divide by the appropriate amount.