コード例 #1
0
        static public BGRImg From(Bitmap source, bool grayscale = false)
        {
            BGRImg     result = new BGRImg(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, t;
            int        scale = source.Width * source.Height;
            byte       g;

            for (i = 0; i < scale; ++i)
            {
                if (!grayscale)
                {
                    for (t = 0; t < 3; ++t)
                    {
                        result[t, i] = Complex.FromRealImaginary(sourcepointer[0], 0);
                        ++sourcepointer;
                    }
                    ++sourcepointer;
                }
                else
                {
                    g              = (byte)((sourcepointer[0] + sourcepointer[1] + sourcepointer[2]) / 3.0D);
                    result[0, i]   = result[1, i] = result[2, i] = Complex.FromRealImaginary(g, 0);
                    sourcepointer += 4;
                }
            }
            source.UnlockBits(sourcedata);
            return(result);
        }
コード例 #2
0
        public BGRImg SimpleMotionDeblur(double length, double lambda)
        {
            BGRImg             oext = Extend();
            SimpleMotionKernel smk  = new SimpleMotionKernel(oext.Width, oext.Height, length);
            BGRImg             rext = new BGRImg(oext.Width, oext.Height);

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

            for (t = 0; t < 3; ++t)
            {
                for (i = 0; i < scale; ++i)
                {
                    smk[i]    += 0.0000001;
                    d          = smk[i].ModulusSquared;
                    s          = d / (d + lambda);
                    rext[t, i] = (oext[t, i] / smk[i]) * s;
                }
            }
            rext.BFFTShift();
            rext.IFFT2();
            return(rext.UnExtend(_Width, _Height));
        }
コード例 #3
0
        public BGRImg Extend()
        {
            int ewidth = (int)Math.Pow(2, ImgF.Log2(_Width)),
                eheight = (int)Math.Pow(2, ImgF.Log2(_Height));
            BGRImg result = new BGRImg(ewidth, eheight);
            int    startx = (ewidth - _Width) / 2,
                   starty = (eheight - _Height) / 2;
            int endx = startx + _Width,
                endy = starty + _Height;
            int ttx, tty;
            int y, x, t;

            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;
                    }

                    for (t = 0; t < 3; ++t)
                    {
                        result[t, x, y] = Complex.FromRealImaginary(this[t, ttx - startx, tty - starty].Real, this[t, ttx - startx, tty - starty].Imag);
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        public BGRImg InsideSimpleMotionDeblur(SimpleMotionKernel smk, double lambda)
        {
            BGRImg rext = new BGRImg(_Width, _Height);
            int    i, t, scale = _Width * _Height;
            double d, s;

            for (t = 0; t < 3; ++t)
            {
                for (i = 0; i < scale; ++i)
                {
                    smk[i]    += 0.0000001;
                    d          = smk[i].ModulusSquared;
                    s          = d / (d + lambda);
                    rext[t, i] = (this[t, i] / smk[i]) * s;
                }
            }
            return(rext);
        }
コード例 #5
0
        public BGRImg UnExtend(int owidth, int oheight)
        {
            BGRImg result = new BGRImg(owidth, oheight);
            int    startx = (_Width - owidth) / 2, starty = (_Height - oheight) / 2;
            int    endx = startx + owidth, endy = starty + oheight;
            int    y, x, t;

            for (y = 0; y < _Height; ++y)
            {
                for (x = 0; x < _Width; ++x)
                {
                    if (x >= startx && y >= starty && x < endx && y < endy)
                    {
                        for (t = 0; t < 3; ++t)
                        {
                            result[t, x - startx, y - starty] = this[t, x, y];
                        }
                    }
                }
            }
            return(result);
        }
コード例 #6
0
        public BGRImg SimpleMotionBlur(double length)
        {
            BGRImg             oext = Extend();
            SimpleMotionKernel smk  = new SimpleMotionKernel(oext.Width, oext.Height, length);
            BGRImg             rext = new BGRImg(oext.Width, oext.Height);

            oext.FFT2();
            smk.FFT2();
            int x, y, t;

            for (y = 0; y < oext.Height; ++y)
            {
                for (x = 0; x < oext.Width; ++x)
                {
                    for (t = 0; t < 3; ++t)
                    {
                        rext[t, x, y] = oext[t, x, y] * smk[x, y];
                    }
                }
            }
            rext.BFFTShift();
            rext.IFFT2();
            return(rext.UnExtend(_Width, _Height));
        }