Beispiel #1
0
    public static Texture2D FilterProcessImage(double d, Texture2D image)
    {
        Texture2D ret = new Texture2D(image.width, image.height, TextureFormat.ARGB32, true);

        // red
        double[,] matrixR = new double[image.width, image.height];
        double[,] matrixG = new double[image.width, image.height];
        double[,] matrixB = new double[image.width, image.height];
        double[,] matrixA = new double[image.width, image.height];

        for (int i = 0; i < image.width; i++)
        {
            for (int j = 0; j < image.height; j++)
            {
                //matrixR[i, j] = grayscaler( image.GetPixel(i, j) ).r;
                Color c = image.GetPixel(i, j);
                matrixR[i, j] = c.r;
                matrixG[i, j] = c.g;
                matrixB[i, j] = c.b;
                matrixA[i, j] = c.a;
            }
        }
        matrixR = Gaussian.GaussianConvolution(matrixR, d);
        matrixG = Gaussian.GaussianConvolution(matrixG, d);
        matrixB = Gaussian.GaussianConvolution(matrixB, d);
        matrixA = Gaussian.GaussianConvolution(matrixA, d);


        for (int i = 0; i < image.width; i++)
        {
            for (int j = 0; j < image.height; j++)
            {
                float valR = (float)System.Math.Min(1.0f, matrixR[i, j]);
                float valG = (float)System.Math.Min(1.0f, matrixG[i, j]);
                float valB = (float)System.Math.Min(1.0f, matrixB[i, j]);
                float valA = (float)System.Math.Min(1.0f, matrixA[i, j]);

                ret.SetPixel(i, j, new Color(valR, valG, valB, valA));
                //ret.SetPixel(i, j, Color.red);
            }
        }

        ret.Apply();

        return(ret);
    }