示例#1
0
        /// <summary>
        /// Appy filter.
        /// </summary>
        /// <param name="bmData">Bitmap data</param>
        private unsafe void ApplyRGB(BitmapData bmData)
        {
            float[][,] rgb = BitmapMatrix.ToRGB(bmData, true);

            this.filter.Apply(rgb[0]);
            this.filter.Apply(rgb[1]);
            this.filter.Apply(rgb[2]);

            BitmapMatrix.FromRGB(rgb, bmData);
            return;
        }
示例#2
0
        /// <summary>
        /// Apply filter.
        /// </summary>
        /// <param name="images">Bitmap array</param>
        /// <returns>Bitmap</returns>
        public Bitmap Apply(params Bitmap[] images)
        {
            // data
            int N = images.GetLength(0);

            float[][][,] data = new float[N][][, ];
            int height = images[0].Height;
            int width  = images[1].Width;

            float[][,] weights = new float[N][, ];

            // to rgb array
            for (int i = 0; i < N; i++)
            {
                data[i] = BitmapMatrix.ToRGB(images[i]);
            }

            // initialize weights
            for (int i = 0; i < N; i++)
            {
                weights[i] = Matrice.One(height, width);
            }

            // applying params
            weights = Mul(weights, Exp(data, this.sigma));

            // normalizing
            float[,] z = new float[height, width];

            for (int i = 0; i < N; i++)
            {
                z = z.Add(weights[i]);
            }

            for (int i = 0; i < N; i++)
            {
                weights[i] = weights[i].Div(z);
            }

            // pyramids
            float[][,] pyrW;
            float[][,] pyrIr;
            float[][,] pyrIg;
            float[][,] pyrIb;

            // outputs
            float[][,] zero = gap.Forward(new float[height, width]);
            float[][,] r    = (float[][, ])zero.Clone();
            float[][,] g    = (float[][, ])zero.Clone();
            float[][,] b    = (float[][, ])zero.Clone();
            int levels = r.GetLength(0);

            // do job
            for (int i = 0; i < N; i++)
            {
                pyrW  = gap.Forward(weights[i]);
                zero  = data[i];
                pyrIr = lap.Forward(zero[0]);
                pyrIg = lap.Forward(zero[1]);
                pyrIb = lap.Forward(zero[2]);

                for (int l = 0; l < levels; l++)
                {
                    z = pyrW[l];

                    r[l] = r[l].Add(z.Mul(pyrIr[l]));
                    g[l] = g[l].Add(z.Mul(pyrIg[l]));
                    b[l] = b[l].Add(z.Mul(pyrIb[l]));
                }
            }

            // reconstruction
            Bitmap bitmap = BitmapMatrix.FromRGB(new float[][, ] {
                lap.Backward(r),
                lap.Backward(g),
                lap.Backward(b)
            });

            return(bitmap);
        }