c# - Homomorphic image filter source code has no effect
问题描述
Take a look at this link.
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?
解决方案
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.
推荐阅读
- python - 根据另一列中列表的长度为列赋值
- html - 为什么我的内容没有在 Bootstrap flex 网格中居中?
- ruby-on-rails - Rails 在 jsonb 字段中包含 where 条件
- java - 为什么我的代码卡在 for 循环中?
- python - Python 怎么知道有人在循环一个字典?
- google-apps-script - 如何在 Google Apps 脚本中获取空白工作表的名称?
- perl - Perl 将 CSV 中的行输入到系统命令变量中
- powershell - Powershell - 与模式中的变量匹配
- javascript - Cloudfront 如何缓存第三方事件跟踪 Javascript 文件以提高页面速度?
- html - 数据锚文本 - Web-scraping rvest 问题