朱莉娅设置颜色映射

时间:2018-04-06 18:50:29

标签: java image algorithm

我正在研究java中的julia。以下是我的代码:

public class ColorJulia {


// return number of iterations to check z is in the Julia set of c
static int julia(Complex c, Complex z, int maximumIterations) {
    for (int t = 0; t < maximumIterations; t++) {
        if (z.abs() > 2.0) return t;
        z = z.times(z).plus(c);
    }
    return maximumIterations - 1;
}


public static void main(String[] args) {
    double real = -0.8;//Double.parseDouble(args[0]);      // a
    double imag = 0.1;//Double.parseDouble(args[1]);      // b
    Complex c = new Complex(real, imag);            // c = a + ib
    double xmin   = -2.0;
    double ymin   = -2.0;
    double width  =  4.0;
    double height =  4.0;

    int n = 512;
    int ITERS  = 256;
    int freq[]=new int[256];

    Arrays.fill(freq, 0);

    Picture picture = new Picture(n, n);


    // read in color map
    Color[] colors = new Color[ITERS];
    for (int t = 0; t < ITERS; t++) 
    {
        int r = t;
        int g = t;
        int b = t;
        colors[t] = new Color(r, g, b);
    }

        for (int col = 0; col < n; col++) 
        {
            for (int row = 0; row < n; row++) 
            {
                double x = xmin + col * width / n;
                double y = ymin + row * height / n;
                Complex z = new Complex(x, y);
                int t = julia(c, z, ITERS);
                freq[t]++;
                Color testPixel = new Color(t,t,t);

                picture.set(col, row, testPixel);
            }
        }

        picture.show();



    for(int i=0;i<256;i++)
    {
        System.out.println("freq " + i + " = " + freq[i]);
    }        

  }

}

现在,我得到的输出图像如下: enter image description here

如何获得具有更好映射的图像,如下图所示? enter image description here

在julia set中,我使用迭代的返回值生成RGB颜色。我不知道如何映射这些颜色以获得更好的图像。

2 个答案:

答案 0 :(得分:0)

我会制作一个直方图,以查看生成的图像中出现频率的颜色值(在哪个值范围内)。 根据这些信息,您可以在颜色图中决定使用。

乍一看,看起来你只是变黑了。直方图将显示是否是这种情况。

如果你发现那个 julia(Complex c, Complex z, int maximumIterations)

始终返回0ITERS-1,您需要增加ITERS才能获得更多不同的值。

<强> P.S。
您还可以在www。中找到许多颜色映射方法 例如  here是一个使用模数循环遍历颜色多次的实现。

答案 1 :(得分:0)

首先更改您的参数。现在,对于您的图像,它是c = -0.8 + 0.1 * i,位于Mandelbrto集(=已连接的Julia集)的周期2分量内。在第二个图像上,它是断开的Juli集(在Mandelbrot集之外),像:c = -0.800043099666580 +0.164138006668392 i

第二个:可能是轨道陷阱算法:

HTH