Skip to content

Commit 1e31559

Browse files
authored
Fixed normalization
Modified normalization to correctly represent the zero-normalized cross correlation
1 parent df488ec commit 1e31559

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

openpiv/pyprocess.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def fft_correlate_images(
722722
# longer exposure for frame B
723723
# image_a = match_histograms(image_a, image_b)
724724

725-
# remove mean background, normalize to 0..1 range
725+
# remove mean, divide by standard deviation
726726
image_a = normalize_intensity(image_a)
727727
image_b = normalize_intensity(image_b)
728728

@@ -747,8 +747,8 @@ def fft_correlate_images(
747747
print(f"correlation method {correlation_method } is not implemented")
748748

749749
if normalized_correlation:
750-
corr = corr/(s2[0]*s2[1]) # for extended search area
751-
corr = np.clip(corr, 0, 1)
750+
corr = corr/(corr.shape[-2]*corr.shape[-1]) # for extended search area
751+
752752
return corr
753753

754754

@@ -780,7 +780,7 @@ def normalize_intensity(window):
780780
tmp = window.std(axis=(-2, -1), keepdims=True)
781781
window = np.divide(window, tmp, out=np.zeros_like(window),
782782
where=(tmp != 0))
783-
return np.clip(window, 0, window.max())
783+
return window
784784

785785

786786
def correlate_windows(window_a, window_b, correlation_method="fft",
@@ -825,9 +825,7 @@ def correlate_windows(window_a, window_b, correlation_method="fft",
825825
It leads to inconsistency of the output
826826
"""
827827

828-
# first we remove the mean to normalize contrast and intensity
829-
# the background level which is take as a mean of the image
830-
# is subtracted
828+
# remove mean, divide by standard deviation
831829
# import pdb; pdb.set_trace()
832830
window_a = normalize_intensity(window_a)
833831
window_b = normalize_intensity(window_b)
@@ -849,7 +847,7 @@ def correlate_windows(window_a, window_b, correlation_method="fft",
849847
else:
850848
print(f"correlation method {correlation_method } is not implemented")
851849

852-
return corr
850+
return corr/(corr.shape[-2]*corr.shape[-1])
853851

854852

855853
def fft_correlate_windows(window_a, window_b,

0 commit comments

Comments
 (0)