user366312
user366312

Reputation: 16988

Calculation of correlation coefficient

In this research article, in the section 4.3.1 (core detection),

enter image description here

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?

If yes, how can I find Correlation-coefficients from that?

Upvotes: 0

Views: 962

Answers (1)

Alexander Kiselev
Alexander Kiselev

Reputation: 446

In article correlation are calculated between two "windows", i.e. between two sets of points, not between two points. if i'm not mistaken, correlation coefficient is a scalar value, not a vector. In signal processing , correlation calculated as sum of multiplications divided by sum of squares of signal values. It may be incorrect in details, but in general, correlation calculated like this:

correlation = sum(S1[i]*S2[i])/sqrt(sum(S1[i]^2 * S2[i]^2));

For 2-dimention case (window) just add second index:

correlation = sum(S1[i,j]*S2[i,j])/sqrt(sum(S1[i,j]^2 * S2[i,j]^2));

Upvotes: 2

Related Questions