Exemple #1
0
        public GrayImg Copy()
        {
            GrayImg result = new GrayImg(_Width, _Height);
            int     i, scale = _Width * _Height;

            for (i = 0; i < scale; ++i)
            {
                result[i] = this[i];
            }
            return(result);
        }
Exemple #2
0
        public GrayImg InsideSimpleMotionDeblur(SimpleMotionKernel smk, double lambda)
        {
            GrayImg rext = new GrayImg(_Width, _Height);
            int     i, scale = _Width * _Height;
            double  d, s;

            for (i = 0; i < scale; ++i)
            {
                smk[i] += 0.0000001;
                d       = smk[i].ModulusSquared;
                s       = d / (d + lambda);
                rext[i] = (this[i] / smk[i]) * s;
            }
            return(rext);
        }
Exemple #3
0
        static public GrayImg From(Bitmap source)
        {
            GrayImg    result        = new GrayImg(source.Width, source.Height);
            BitmapData sourcedata    = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            byte *     sourcepointer = (byte *)sourcedata.Scan0.ToPointer();
            int        i;
            int        scale = source.Width * source.Height;
            byte       g;

            for (i = 0; i < scale; ++i)
            {
                g              = (byte)((sourcepointer[0] + sourcepointer[1] + sourcepointer[2]) / 3.0D);
                result[i]      = Complex.FromRealImaginary(g, 0);
                sourcepointer += 4;
            }
            source.UnlockBits(sourcedata);
            return(result);
        }
Exemple #4
0
        public GrayImg UnExtend(int owidth, int oheight)
        {
            GrayImg result = new GrayImg(owidth, oheight);
            int     startx = (_Width - owidth) / 2, starty = (_Height - oheight) / 2;
            int     endx = startx + owidth, endy = starty + oheight;
            int     y, x;

            for (y = 0; y < _Height; ++y)
            {
                for (x = 0; x < _Width; ++x)
                {
                    if (x >= startx && y >= starty && x < endx && y < endy)
                    {
                        result[x - startx, y - starty] = this[x, y];
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        public GrayImg Extend()
        {
            int ewidth = (int)Math.Pow(2, ImgF.Log2(_Width)),
                eheight = (int)Math.Pow(2, ImgF.Log2(_Height));
            GrayImg result = new GrayImg(ewidth, eheight);
            int     startx = (ewidth - _Width) / 2,
                    starty = (eheight - _Height) / 2;
            int endx = startx + _Width,
                endy = starty + _Height;
            int ttx, tty;
            int y, x;

            for (y = 0; y < eheight; ++y)
            {
                for (x = 0; x < ewidth; ++x)
                {
                    ttx = x;
                    tty = y;
                    while (ttx - startx < 0)
                    {
                        ttx += Math.Abs(ttx - startx) * 2 - 1;
                    }
                    while (ttx - startx >= _Width)
                    {
                        ttx -= Math.Abs(ttx - startx - _Width) * 2 + 1;
                    }
                    while (tty - starty < 0)
                    {
                        tty += Math.Abs(tty - starty) * 2 - 1;
                    }
                    while (tty - starty >= _Height)
                    {
                        tty -= Math.Abs(tty - starty - _Height) * 2 + 1;
                    }
                    result[x, y] = Complex.FromRealImaginary(this[ttx - startx, tty - starty].Real, this[ttx - startx, tty - starty].Imag);
                }
            }
            return(result);
        }
Exemple #6
0
        public GrayImg SimpleMotionDeblur(double length, double lambda)
        {
            GrayImg            oext = Extend();
            SimpleMotionKernel smk  = new SimpleMotionKernel(oext.Width, oext.Height, length);
            GrayImg            rext = new GrayImg(oext.Width, oext.Height);

            oext.FFT2();
            smk.FFT2();
            int    i, scale = oext.Width * oext.Height;
            double d, s;

            for (i = 0; i < scale; ++i)
            {
                smk[i] += 0.0000001;
                d       = smk[i].ModulusSquared;
                s       = d / (d + lambda);
                rext[i] = (oext[i] / smk[i]) * s;
            }
            rext.BFFTShift();
            rext.IFFT2();
            return(rext.UnExtend(_Width, _Height));
        }