首页 > 解决方案 > Homomorphic image filter source code has no effect

问题描述

Take a look at this link.

enter image description here

public struct COMPLEX
{
    public double real, imag;
    public Complex(double x, double y)
    {
        real = x;
        imag = y;
    }
    public float Magnitude()
    {
        return ((float)Math.Sqrt(real * real + imag * imag));
    }
    public float Phase()
    {            
         return ((float)Math.Atan(imag / real));
    }
}

public static COMPLEX[,] ApplyFilterHMMFreqDomain(COMPLEX[,] FFTData, 
              float rH, float rL, float Sigma, float Slope)
{
    COMPLEX[,] Output = new COMPLEX[FFTData.GetLength(0), FFTData.GetLength(1)];
    int i, j, W, H;

    W = FFTData.GetLength(0);
    H = FFTData.GetLength(1);

    double Weight;
    //Taking FFT of Gaussian HPF
    double[,] GaussianHPF = 
      GenerateGaussianKernelHPF(FFTData.GetLength(0), Sigma, Slope, out Weight);

    //Variables for FFT of Gaussian Filter
    COMPLEX[,] GaussianHPFFFT;


    for (i = 0; i <= GaussianHPF.GetLength(0) - 1; i++)
        for (j = 0; j <= GaussianHPF.GetLength(1) - 1; j++)
        {
            GaussianHPF[i, j] = GaussianHPF[i, j];// / Weight;
        }

    FFT GaussianFFTObject = new FFT(GaussianHPF);
    GaussianFFTObject.ForwardFFT(GaussianHPF);
    //Shifting FFT for Filtering
    GaussianFFTObject.FFTShift();


    GaussianHPFFFT = GaussianFFTObject.FFTShifted;
    for (i = 0; i <= GaussianHPF.GetLength(0) - 1; i++)
        for (j = 0; j <= GaussianHPF.GetLength(1) - 1; j++)
        {
            GaussianHPFFFT[i, j].real = (rH - rL) * GaussianHPFFFT[i, j].real + rL;
            GaussianHPFFFT[i, j].imag = (rH - rL) * GaussianHPFFFT[i, j].imag + rL;
        }

    // Applying Filter on the FFT of the Log Image by Multiplying in Frequency Domain
    Output = MultiplyFFTMatrices(GaussianHPFFFT, FFTData);

    return Output;
}

After detail experiment, I found no or insignificant effect of the following snippet of source code:

for (i = 0; i <= GaussianHPF.GetLength(0) - 1; i++)
    for (j = 0; j <= GaussianHPF.GetLength(1) - 1; j++)
    {
        GaussianHPFFFT[i, j].real = (rH - rL) * GaussianHPFFFT[i, j].real + rL;
        GaussianHPFFFT[i, j].imag = (rH - rL) * GaussianHPFFFT[i, j].imag + rL;
    }

Can anyone explain why this part of the code is/isn't important?

标签: c#image-processing

解决方案


That snippet of code applies the same linear transformation to each value of the frequency domain. This is equivalent to applying the same transformation to each pixel in the spatial domain (the Fourier transform is linear)

The linear transformation and the convolution commute, as is easy to see since the convolution is a multiplication in the frequency domain, you can clearly swap these two operations there.

Thus, you are applying this constant, linear transformation to the output of the filter. If you display the output by linearly scaling the values to the output range, you will undo any effect of this transformation.

My guess is that it’s there to scale the output spatial-domain image to a meaningful range.


推荐阅读