.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/transform/plot_rescale.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_transform_plot_rescale.py: ============================== Rescale, resize, and downscale ============================== `Rescale` operation resizes an image by a given scaling factor. The scaling factor can either be a single floating point value, or multiple values - one along each axis. `Resize` serves the same purpose, but allows to specify an output image shape instead of a scaling factor. Note that when down-sampling an image, `resize` and `rescale` should perform Gaussian smoothing to avoid aliasing artifacts. See the `anti_aliasing` and `anti_aliasing_sigma` arguments to these functions. `Downscale` serves the purpose of down-sampling an n-dimensional image by integer factors using the local mean on the elements of each block of the size factors given as a parameter to the function. .. GENERATED FROM PYTHON SOURCE LINES 22-55 .. image-sg:: /auto_examples/transform/images/sphx_glr_plot_rescale_001.png :alt: Original image, Rescaled image (aliasing), Resized image (no aliasing), Downscaled image (no aliasing) :srcset: /auto_examples/transform/images/sphx_glr_plot_rescale_001.png :class: sphx-glr-single-img .. code-block:: default import matplotlib.pyplot as plt from skimage import data, color from skimage.transform import rescale, resize, downscale_local_mean image = color.rgb2gray(data.astronaut()) image_rescaled = rescale(image, 0.25, anti_aliasing=False) image_resized = resize(image, (image.shape[0] // 4, image.shape[1] // 4), anti_aliasing=True) image_downscaled = downscale_local_mean(image, (4, 3)) fig, axes = plt.subplots(nrows=2, ncols=2) ax = axes.ravel() ax[0].imshow(image, cmap='gray') ax[0].set_title("Original image") ax[1].imshow(image_rescaled, cmap='gray') ax[1].set_title("Rescaled image (aliasing)") ax[2].imshow(image_resized, cmap='gray') ax[2].set_title("Resized image (no aliasing)") ax[3].imshow(image_downscaled, cmap='gray') ax[3].set_title("Downscaled image (no aliasing)") ax[0].set_xlim(0, 512) ax[0].set_ylim(512, 0) plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.646 seconds) .. _sphx_glr_download_auto_examples_transform_plot_rescale.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.22.x?filepath=notebooks/auto_examples/transform/plot_rescale.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_rescale.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_rescale.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_