在这篇研究文章中,在4.3.1 (core detection)部分,
How can I calculate correlation coefficients between two pixels?
public static Complex[,] Correlation(Complex[,]image, Complex[,]mask)
{
Complex[,] convolve = null;
int imageWidth = image.GetLength(0);
int imageHeight = image.GetLength(1);
int maskWidth = mask.GetLength(0);
int maskeHeight = mask.GetLength(1);
if (imageWidth == maskWidth && imageHeight == maskeHeight)
{
FourierTransform ftForImage = new FourierTransform(image); ftForImage.ForwardFFT();
FourierTransform ftForMask = new FourierTransform(mask); ftForMask.ForwardFFT();
Complex[,] fftImage = ftForImage.FourierImageComplex;
Complex[,] fftKernel = ftForMask.FourierImageComplex;
Complex[,] fftConvolved = new Complex[imageWidth, imageHeight];
for (int j = 0; j < imageHeight; j++)
{
for (int i = 0; i < imageWidth; i++)
{
fftConvolved[i,j] = Complex.Conjugate(fftImage[i,j]) * fftKernel[i,j];
}
}
FourierTransform ftForConv = new FourierTransform();
ftForConv.InverseFFT(fftConvolved);
convolve = ftForConv.GrayscaleImageComplex;
Rescale(convolve);
convolve = FourierShifter.FFTShift(convolve);
}
else
{
throw new Exception("padding needed");
}
return convolve;
}
Is this the correct procedure to calculate correlations?
如果是,我怎样才能找到相关系数?
1 回答
在文章中,在两个“窗口”之间计算相关性,即在两组点之间,而不是在两个点之间 . 如果我没有弄错,相关系数是标量值,而不是矢量 . 在信号处理中,相关性被计算为乘法之和除以信号值的平方和 . 它的细节可能不正确,但一般来说,相关计算如下:
对于二维情况(窗口),只需添加第二个索引: