Repository: scikit-image/scikit-image

Issue:
Gallery example 'Using Polar and Log-Polar Transformations for Registration' needs fixing
## Description
The gallery example for Using Polar and Log-Polar Transformations for Registration seems to be broken as of 0.19.x. Was working in 0.18.x.

## Way to reproduce
Unsure if this is specific to the production doc build or an issue in the code. I am raising this issue to get it on the board before starting my testing.


## Version information
See description. I'll report back in this thread when I know more.



Discussion:
The `phase_cross_correlation` normalization parameter seems to be causing the trouble here. This parameter defaults to "phase" in 0.19.2. When I set to `None`, values seem to match 0.18.3 behavior. I'll do some more rigorous testing and if this holds up, will submit a PR with the fix.
I think we had considered that change a bug fix, so we didn't have the usual deprecation cycle. Fortunately, we did keep the option to use the old behavior, so it is likely the fix will just require updating the demo.
found the prior discussion: https://github.com/scikit-image/scikit-image/pull/5461#issuecomment-907785652
@grlee77 My plan was to just drop `normalization=None` in all of the relevant positions in that gallery example, but I wanted to understand what was going on a little better first. I can't quite understand why the approach wouldn't be at least somewhat robust to that normalization, but maybe it's because the starting image is itself polar-log transformed frequency space? It's making my head hurt a bit to think through.

I'll update the demo and submit.
Yeah, I agree it would be better to understand a bit better. I don't have a good intuition for it, but perhaps some debugging looking at intermediate results within the `phase_cross_correlation` function can provide some idea.

Resolving patch:
diff --git a/doc/examples/registration/plot_register_rotation.py b/doc/examples/registration/plot_register_rotation.py
--- a/doc/examples/registration/plot_register_rotation.py
+++ b/doc/examples/registration/plot_register_rotation.py
@@ -60,7 +60,9 @@
 ax[3].imshow(rotated_polar)
 plt.show()
 
-shifts, error, phasediff = phase_cross_correlation(image_polar, rotated_polar)
+shifts, error, phasediff = phase_cross_correlation(image_polar,
+                                                   rotated_polar,
+                                                   normalization=None)
 print(f'Expected value for counterclockwise rotation in degrees: '
       f'{angle}')
 print(f'Recovered value for counterclockwise rotation: '
@@ -102,7 +104,8 @@
 
 # setting `upsample_factor` can increase precision
 shifts, error, phasediff = phase_cross_correlation(image_polar, rescaled_polar,
-                                                   upsample_factor=20)
+                                                   upsample_factor=20,
+                                                   normalization=None)
 shiftr, shiftc = shifts[:2]
 
 # Calculate scale factor from translation
@@ -151,7 +154,8 @@
 warped_image = warp_polar(image, radius=radius, scaling="log")
 warped_rts = warp_polar(rts_image, radius=radius, scaling="log")
 shifts, error, phasediff = phase_cross_correlation(warped_image, warped_rts,
-                                                   upsample_factor=20)
+                                                   upsample_factor=20,
+                                                   normalization=None)
 shiftr, shiftc = shifts[:2]
 klog = radius / np.log(radius)
 shift_scale = 1 / (np.exp(shiftc / klog))
@@ -209,7 +213,8 @@
 warped_rts_fs = warped_rts_fs[:shape[0] // 2, :]
 shifts, error, phasediff = phase_cross_correlation(warped_image_fs,
                                                    warped_rts_fs,
-                                                   upsample_factor=10)
+                                                   upsample_factor=10,
+                                                   normalization=None)
 
 # Use translation parameters to calculate rotation and scaling parameters
 shiftr, shiftc = shifts[:2]


Test patch: