.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\scipy\demo_Scipy.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_python_packages_scipy_demo_Scipy.py: Scipy ======= Opens the ascent image from ``scipy.misc`` and shifts the image. Finally, the shift offsets are determined using cross-correlation. .. GENERATED FROM PYTHON SOURCE LINES 7-14 .. code-block:: Python import scipy.misc import numpy from numpy.fft import fft2 from numpy.fft import fftshift import pylab .. GENERATED FROM PYTHON SOURCE LINES 16-17 Get the ascent image and calculate an offset shift. .. GENERATED FROM PYTHON SOURCE LINES 17-41 .. code-block:: Python ascent = scipy.misc.ascent() print("The ascent-image has a size of", ascent.shape) print("The maximum value of this image is ", ascent.max()) print("Its data type is ", ascent.dtype) F = fft2(ascent) F2 = fftshift(F) pylab.figure() pylab.gray() pylab.subplot(221) pylab.imshow(ascent) pylab.title("ascent (Original)") pylab.subplot(222) img = pylab.imshow(numpy.real(F)) img.set_clim(0, 100) pylab.title("ascent (FFT)") pylab.subplot(223) img = pylab.imshow(numpy.real(F2)) img.set_clim(0, 100) pylab.title("ascent (FFT), fftshift") .. image-sg:: /11_demos/python_packages/scipy/images/sphx_glr_demo_Scipy_001.png :alt: ascent (Original), ascent (FFT), ascent (FFT), fftshift :srcset: /11_demos/python_packages/scipy/images/sphx_glr_demo_Scipy_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none C:\Workspace\itom_development_VS2019_Qt5.15.2_x64\itomProject\itom\demo\python_packages\scipy\demo_Scipy.py:17: DeprecationWarning: scipy.misc.ascent has been deprecated in SciPy v1.10.0; and will be completely removed in SciPy v1.12.0. Dataset methods have moved into the scipy.datasets module. Use scipy.datasets.ascent instead. The ascent-image has a size of (512, 512) The maximum value of this image is 255 Its data type is int32 Text(0.5, 1.0, 'ascent (FFT), fftshift') .. GENERATED FROM PYTHON SOURCE LINES 42-43 Calculate the cross-correlation. .. GENERATED FROM PYTHON SOURCE LINES 43-85 .. code-block:: Python pylab.figure() pylab.subplot(231) pylab.imshow(ascent) ascent_roll = numpy.roll(ascent, 50, 1) ascent_roll = numpy.roll(ascent_roll, -150, 0) pylab.subplot(232) pylab.imshow(ascent_roll) F = fftshift(fft2(ascent)) F2 = fftshift(fft2(ascent_roll)) F3 = numpy.multiply(F, F2.conj()) F4 = fftshift(numpy.fft.ifft2(F3)) pylab.subplot(233) img = pylab.imshow(numpy.real(F)) img.set_clim(0, 100) pylab.subplot(234) img = pylab.imshow(numpy.real(F2)) img.set_clim(0, 100) pylab.subplot(235) img = pylab.imshow(numpy.real(F3)) img.set_clim(0, 100) pylab.subplot(236) F5 = numpy.real(F4) img = pylab.imshow(F5, vmin=0, vmax=0.001) max_pos = numpy.argmax(F5) offset_x = max_pos % 512 offset_y = (max_pos - offset_x) / 512 print("offset_x: ", offset_x - 256) print("offset_y: ", offset_y - 256) pylab.show() .. image-sg:: /11_demos/python_packages/scipy/images/sphx_glr_demo_Scipy_002.png :alt: demo Scipy :srcset: /11_demos/python_packages/scipy/images/sphx_glr_demo_Scipy_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none offset_x: -50 offset_y: 150.0 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.417 seconds) .. _sphx_glr_download_11_demos_python_packages_scipy_demo_Scipy.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_Scipy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_Scipy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_Scipy.zip `