vlt.image.corrcoef
CORRCOEF - Computes a 2D spatial cross-correlation coefficient map.
C = vlt.image.corrcoef(IMAGE1, IMAGE2, MASK1, MASK2, N)
Calculates the 2D cross-correlation coefficient between two images for a
range of spatial shifts up to N pixels in x and y. The correlation is
only computed over pixels that are valid in both provided masks.
The function leverages the symmetry of the correlation coefficient,
C(dy, dx) = C(-dy, -dx), to reduce computations by about half.
Inputs:
IMAGE1 - The first 2D data matrix.
IMAGE2 - The second 2D data matrix, must be the same size as IMAGE1.
MASK1 - A logical matrix of the same size as IMAGE1. True values
indicate valid pixels to be included in the correlation.
MASK2 - A logical matrix for IMAGE2, same size and meaning as MASK1.
N - A scalar integer specifying the maximum shift in pixels for
the correlation calculation. The output will be (2N+1)x(2N+1).
Outputs:
C - A (2N+1)x(2N+1) matrix containing the correlation coefficients.
The center of the matrix (C(N+1, N+1)) corresponds to a
zero-pixel shift.
Example:
img = rand(100);
img_shifted = circshift(img, [5 10]);
mask = true(100);
C = vlt.image.corrcoef(img, img_shifted, mask, mask, 20);
figure;
imagesc(-20:20, -20:20, C);
colorbar;
title('Spatial Cross-Correlation');
xlabel('X Shift (pixels)'); ylabel('Y Shift (pixels)');