Esempio n. 1
0
        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));
        }