"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "doc/examples/registration/plot_register_rotation.py" between
scikit-image-0.19.2.tar.gz and scikit-image-0.19.3.tar.gz

About: scikit-image is a collection of algorithms for image processing in Python.

plot_register_rotation.py  (scikit-image-0.19.2):plot_register_rotation.py  (scikit-image-0.19.3)
skipping to change at line 63 skipping to change at line 63
ax[0].set_title("Original") ax[0].set_title("Original")
ax[0].imshow(image) ax[0].imshow(image)
ax[1].set_title("Rotated") ax[1].set_title("Rotated")
ax[1].imshow(rotated) ax[1].imshow(rotated)
ax[2].set_title("Polar-Transformed Original") ax[2].set_title("Polar-Transformed Original")
ax[2].imshow(image_polar) ax[2].imshow(image_polar)
ax[3].set_title("Polar-Transformed Rotated") ax[3].set_title("Polar-Transformed Rotated")
ax[3].imshow(rotated_polar) ax[3].imshow(rotated_polar)
plt.show() 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: ' print(f'Expected value for counterclockwise rotation in degrees: '
f'{angle}') f'{angle}')
print(f'Recovered value for counterclockwise rotation: ' print(f'Recovered value for counterclockwise rotation: '
f'{shifts[0]}') f'{shifts[0]}')
###################################################################### ######################################################################
# Recover rotation and scaling differences with log-polar transform # Recover rotation and scaling differences with log-polar transform
# ================================================================= # =================================================================
# #
# In this second example, the images differ by both rotation and scaling (note # In this second example, the images differ by both rotation and scaling (note
skipping to change at line 105 skipping to change at line 107
ax[1].set_title("Rotated and Rescaled") ax[1].set_title("Rotated and Rescaled")
ax[1].imshow(rescaled) ax[1].imshow(rescaled)
ax[2].set_title("Log-Polar-Transformed Original") ax[2].set_title("Log-Polar-Transformed Original")
ax[2].imshow(image_polar) ax[2].imshow(image_polar)
ax[3].set_title("Log-Polar-Transformed Rotated and Rescaled") ax[3].set_title("Log-Polar-Transformed Rotated and Rescaled")
ax[3].imshow(rescaled_polar) ax[3].imshow(rescaled_polar)
plt.show() plt.show()
# setting `upsample_factor` can increase precision # setting `upsample_factor` can increase precision
shifts, error, phasediff = phase_cross_correlation(image_polar, rescaled_polar, shifts, error, phasediff = phase_cross_correlation(image_polar, rescaled_polar,
upsample_factor=20) upsample_factor=20,
normalization=None)
shiftr, shiftc = shifts[:2] shiftr, shiftc = shifts[:2]
# Calculate scale factor from translation # Calculate scale factor from translation
klog = radius / np.log(radius) klog = radius / np.log(radius)
shift_scale = 1 / (np.exp(shiftc / klog)) shift_scale = 1 / (np.exp(shiftc / klog))
print(f'Expected value for cc rotation in degrees: {angle}') print(f'Expected value for cc rotation in degrees: {angle}')
print(f'Recovered value for cc rotation: {shiftr}') print(f'Recovered value for cc rotation: {shiftr}')
print() print()
print(f'Expected value for scaling difference: {scale}') print(f'Expected value for scaling difference: {scale}')
skipping to change at line 154 skipping to change at line 157
rotated = rotate(translated, angle) rotated = rotate(translated, angle)
rescaled = rescale(rotated, scale) rescaled = rescale(rotated, scale)
sizer, sizec = image.shape sizer, sizec = image.shape
rts_image = rescaled[:sizer, :sizec] rts_image = rescaled[:sizer, :sizec]
# When center is not shared, log-polar transform is not helpful! # When center is not shared, log-polar transform is not helpful!
radius = 705 radius = 705
warped_image = warp_polar(image, radius=radius, scaling="log") warped_image = warp_polar(image, radius=radius, scaling="log")
warped_rts = warp_polar(rts_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, shifts, error, phasediff = phase_cross_correlation(warped_image, warped_rts,
upsample_factor=20) upsample_factor=20,
normalization=None)
shiftr, shiftc = shifts[:2] shiftr, shiftc = shifts[:2]
klog = radius / np.log(radius) klog = radius / np.log(radius)
shift_scale = 1 / (np.exp(shiftc / klog)) shift_scale = 1 / (np.exp(shiftc / klog))
fig, axes = plt.subplots(2, 2, figsize=(8, 8)) fig, axes = plt.subplots(2, 2, figsize=(8, 8))
ax = axes.ravel() ax = axes.ravel()
ax[0].set_title("Original Image") ax[0].set_title("Original Image")
ax[0].imshow(image, cmap='gray') ax[0].imshow(image, cmap='gray')
ax[1].set_title("Modified Image") ax[1].set_title("Modified Image")
ax[1].imshow(rts_image, cmap='gray') ax[1].imshow(rts_image, cmap='gray')
skipping to change at line 212 skipping to change at line 216
radius = shape[0] // 8 # only take lower frequencies radius = shape[0] // 8 # only take lower frequencies
warped_image_fs = warp_polar(image_fs, radius=radius, output_shape=shape, warped_image_fs = warp_polar(image_fs, radius=radius, output_shape=shape,
scaling='log', order=0) scaling='log', order=0)
warped_rts_fs = warp_polar(rts_fs, radius=radius, output_shape=shape, warped_rts_fs = warp_polar(rts_fs, radius=radius, output_shape=shape,
scaling='log', order=0) scaling='log', order=0)
warped_image_fs = warped_image_fs[:shape[0] // 2, :] # only use half of FFT warped_image_fs = warped_image_fs[:shape[0] // 2, :] # only use half of FFT
warped_rts_fs = warped_rts_fs[:shape[0] // 2, :] warped_rts_fs = warped_rts_fs[:shape[0] // 2, :]
shifts, error, phasediff = phase_cross_correlation(warped_image_fs, shifts, error, phasediff = phase_cross_correlation(warped_image_fs,
warped_rts_fs, warped_rts_fs,
upsample_factor=10) upsample_factor=10,
normalization=None)
# Use translation parameters to calculate rotation and scaling parameters # Use translation parameters to calculate rotation and scaling parameters
shiftr, shiftc = shifts[:2] shiftr, shiftc = shifts[:2]
recovered_angle = (360 / shape[0]) * shiftr recovered_angle = (360 / shape[0]) * shiftr
klog = shape[1] / np.log(radius) klog = shape[1] / np.log(radius)
shift_scale = np.exp(shiftc / klog) shift_scale = np.exp(shiftc / klog)
fig, axes = plt.subplots(2, 2, figsize=(8, 8)) fig, axes = plt.subplots(2, 2, figsize=(8, 8))
ax = axes.ravel() ax = axes.ravel()
ax[0].set_title("Original Image FFT\n(magnitude; zoomed)") ax[0].set_title("Original Image FFT\n(magnitude; zoomed)")
 End of changes. 4 change blocks. 
4 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)