コード例 #1
0
ファイル: ImgF.cs プロジェクト: daniel-code/104NSYSUDIPFPCS
        static public Bitmap SimpleMotionBlur(Bitmap Source, float Length)
        {
            int OWidth = Source.Width, OHeight = Source.Height;

            Source = ImgExtend(Source, true);
            int           Width = Source.Width, Height = Source.Height;
            var           ComplexKernel = SimpleComplexKernel(Width, Height, Length, true);
            int           X, Y, T;
            BGRComplexImg ComplexSource = Img2BGRComplexImg(Source, true);
            BGRComplexImg ComplexResult = new BGRComplexImg(Width, Height);

            ComplexSource.FFT2();
            AMFT.FFT2(ComplexKernel, AMFT.Direction.Forward);
            for (Y = 0; Y < Height; ++Y)
            {
                for (X = 0; X < Width; ++X)
                {
                    for (T = 0; T < 3; ++T)
                    {
                        ComplexResult[T][Y, X] = ComplexSource[T][Y, X] * ComplexKernel[Y, X];
                    }
                }
            }
            ComplexResult.BFFTShift();
            ComplexResult.IFFT2();
            Bitmap Result = BGRComplexImg2Img(ComplexResult);

            return(ImgUnExtend(Result, OWidth, OHeight));
        }
コード例 #2
0
ファイル: ImgF.cs プロジェクト: daniel-code/104NSYSUDIPFPCS
        static public Bitmap HomomorphicFilter(Bitmap Source, double GammaHigh = 2, double GammaLow = 0.25, double C = 1, double D0 = 80)
        {
            int OWidth = Source.Width, OHeight = Source.Height;

            Source = ImgExtend(Source);
            int           Width = Source.Width, Height = Source.Height;
            int           X, Y, T;
            double        D = GammaHigh - GammaLow, P, W, G;
            BGRComplexImg ComplexSource = Img2BGRComplexImg(Source);

            //ComplexSource.ToDouble();
            ComplexSource.BFFTShift();
            ComplexSource.Ln();
            ComplexSource.FFT2();
            for (Y = 0; Y < Height; ++Y)
            {
                for (X = 0; X < Width; ++X)
                {
                    P = -C * ((Math.Pow(Y - (Height / 2), 2) + Math.Pow(X - (Width / 2), 2)) / (Math.Pow(D0, 2)));
                    W = (1 - Math.Exp(P));
                    G = (D * W) + GammaLow;
                    for (T = 0; T < 3; ++T)
                    {
                        ComplexSource[T][Y, X] *= G;
                    }
                }
            }
            ComplexSource.IFFT2();
            ComplexSource.Exp();
            ComplexSource.BFFTShift();
            //ComplexSource.Range();
            Bitmap Result = BGRComplexImg2Img(ComplexSource);

            return(ImgUnExtend(Result, OWidth, OHeight));
        }
コード例 #3
0
ファイル: ImgF.cs プロジェクト: daniel-code/104NSYSUDIPFPCS
        static public Bitmap Deconvolution(Bitmap SourceA, Bitmap SourceB, double Lambda = 10, bool Zero = false)
        {
            int OWidth = SourceA.Width, OHeight = SourceA.Height;

            if (OWidth != SourceB.Width || OHeight != SourceB.Height)
            {
                throw new Exception("圖片大小不一");
            }
            SourceA = ImgExtend(SourceA, Zero);
            SourceB = ImgExtend(SourceB, Zero);
            int           Width = SourceA.Width, Height = SourceA.Height;
            int           X, Y, T;
            BGRComplexImg ComplexSourceA = Img2BGRComplexImg(SourceA);
            BGRComplexImg ComplexSourceB = Img2BGRComplexImg(SourceB);
            BGRComplexImg ComplexResult  = new BGRComplexImg(Width, Height);

            ComplexSourceA.FFT2();
            ComplexSourceB.FFT2();
            for (Y = 0; Y < Height; ++Y)
            {
                for (X = 0; X < Width; ++X)
                {
                    for (T = 0; T < 3; ++T)
                    {
                        ComplexResult[T][Y, X] = AMComplex.MaxDivide(ComplexSourceA[T][Y, X], ComplexSourceB[T][Y, X]) * (ComplexSourceA[T][Y, X].Magnitude / (ComplexSourceA[T][Y, X].Magnitude + Lambda));
                    }
                }
            }
            ComplexResult.BFFTShift();
            ComplexResult.IFFT2();
            Bitmap Result = BGRComplexImg2Img(ComplexResult);

            return(ImgUnExtend(Result, OWidth, OHeight));
        }