cophus / scanning-drift-corr

Correction of nonlinear and linear scanning probe artifacts using orthogonal scan pairs.
13 stars 6 forks source link

Hybrid correlation? #4

Open thomasaarholt opened 5 years ago

thomasaarholt commented 5 years ago

Hiya @cophus ,

Just out of curiosity, where did you discover this algorithm? It looks like some sort of cross correlation, but I haven't been able to dig up any info on it. What is it?

m = fft2(w2.*sMerge.imageTransform(:,:,1)) ...
            .* conj(fft2(w2.*sMerge.imageTransform(:,:,2)));
Icorr  = ifft2(sqrt(abs(m)).*exp(1i*angle(m)),'symmetric')

https://github.com/cophus/scanning-drift-corr/blob/2ae74ef40d9db247670021623fdf12881606f4c7/matlab/SPmerge01linear.m#L106

cophus commented 5 years ago

Hi Thomas,

It's my own idea - however it seems like such an obvious idea I strongly doubt I am the first! The basic theory is based on the cross correlation, where: image_corr_cross = ifft2( fft2( image01 ) .* conj( fft2( image02) ), 'symmetric' );

and phase correlation, where: m = fft2( image01 ) .* conj( fft2( image02) ); image_corr_phase = ifft2( m ./ abs( m ) , 'symmetric');

Note the stable form of phase correlation is: image_corr_phase = ifft2( exp( i * angle( m ) ), 'symmetric');

So my initial idea was a "hybrid" correlation, where we take the geometric mean of cross and phase correlation. Meaning: image_corr_phase = ifft2( abs(m).^0.0 . exp( i angle( m ) ), 'symmetric'); image_corr_hybrid = ifft2( abs(m).^0.5 . exp( i angle( m ) ), 'symmetric'); image_corr_cross = ifft2( abs(m).^1.0 . exp( i angle( m ) ), 'symmetric');

The idea is to get the precision of phase correlation, with the robustness of cross correlation. I explored this idea in the paper on NBED strain that Tom wrote up: https://www.sciencedirect.com/science/article/abs/pii/S0304399116304065

Since then I have generalized this idea to any power law for correlation: image_corr_hybrid = ifft2( abs(m).^p . exp( i angle( m ) ), 'symmetric'); where 0 <= p <= 1 We usually use p = 0.9 ish in py4DSTEM for example: https://github.com/py4dstem/py4DSTEM

Let me know if you have any other questions!