コード例 #1
0
 /// <summary>
 /// Appy filter.
 /// </summary>
 /// <param name="bmData">Bitmap data</param>
 private unsafe void ApplyGrayscale(BitmapData bmData)
 {
     float[,] y = BitmapMatrix.ToGrayscale(bmData);
     this.filter.Apply(y);
     BitmapMatrix.FromGrayscale(y, bmData);
     return;
 }
コード例 #2
0
 /// <summary>
 /// Appy filter.
 /// </summary>
 /// <param name="bmData">Bitmap data</param>
 private unsafe void ApplyYCbCr(BitmapData bmData)
 {
     float[][,] ycbcr = BitmapMatrix.ToYCbCr(bmData, true);
     this.filter.Apply(ycbcr[0]);
     BitmapMatrix.FromYCbCr(ycbcr, bmData);
     return;
 }
コード例 #3
0
 /// <summary>
 /// Appy filter.
 /// </summary>
 /// <param name="bmData">Bitmap data</param>
 private unsafe void ApplyHSL(BitmapData bmData)
 {
     float[][,] hsl = BitmapMatrix.ToHSL(bmData, true);
     this.filter.Apply(hsl[2]);
     BitmapMatrix.FromHSL(hsl, bmData);
     return;
 }
コード例 #4
0
        /// <summary>
        /// Converts a Bitmap to an YCbCr structure with or without alpha-channel.
        /// </summary>
        /// <param name="Data">Bitmap</param>
        /// <param name="alpha">Alpha-channel</param>
        /// <returns>YCbCr structure array</returns>
        public static float[][,] ToYCbCr(this Bitmap Data, bool alpha = false)
        {
            BitmapData bmData = BitmapFormat.Lock32bpp(Data);

            float[][,] rgb = BitmapMatrix.ToYCbCr(bmData, alpha);
            BitmapFormat.Unlock(Data, bmData);
            return(rgb);
        }
コード例 #5
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;
        }
コード例 #6
0
ファイル: StereoDisparity.cs プロジェクト: asiryan/UMapx
        /// <summary>
        /// Apply filter.
        /// </summary>
        /// <param name="bmData">Bitmap data</param>
        /// <param name="bmSrc">Bitmap data</param>
        public float[,] Apply(BitmapData bmData, BitmapData bmSrc)
        {
            // images to matrices
            var left  = BitmapMatrix.ToGrayscale(bmData);
            var right = BitmapMatrix.ToGrayscale(bmSrc);

            // apply filter
            var output = disparity_estimator(left, right, Window, Disparity, Weight, Smoothing);

            // return result
            return(output);
        }
コード例 #7
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);
        }