
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image - Scaling an image
Scaling an image refers to the process of resizing an image in computer graphics and digital image processing tasks. This includes making an image either larger (upscaling) or smaller (downscaling). And this process is also commonly used in various fields, like graphics design, web development, and multimedia.
Scaling images involves applying transformations that alter the size or resolution of an image. These transformations useful for various purposes, such as reducing the size of an image through down-sampling or enhancing its resolution through up-sampling. For instance the scikit-image library provides functions like transform.resize() and transform.rescale() to perform these scaling operations.
Using the skimage.transform.resize() function
The skimage.transform.resize() function allows you to resize an N-dimensional image to a specified output shape. This function performs interpolation to either up-size or down-size the image.
This function is particularly useful for resizing images while handling various interpolation methods and boundary conditions. It is recommended to enable anti-aliasing when downsizing images to avoid aliasing artifacts.
Syntax
Following is the syntax of this method −
skimage.transform.resize(image, output_shape, order=None, mode='reflect', cval=0, clip=True, preserve_range=False, anti_aliasing=None, anti_aliasing_sigma=None)
Parameters
- image: The input image you want to resize (an N-dimensional NumPy array).
- output_shape: The size of the generated output image, specified as an iterable (e.g., (rows, cols[, ][, dim])). If dim is not provided, the number of channels is preserved. If the number of input channels differs from the output channels, an n-dimensional interpolation is applied.
- order (optional): The order of spline interpolation, ranging from 0 to 5. Default is 0 for boolean images and 1 otherwise.
- mode (optional): Determines how points outside the input image boundaries are filled. Options include 'constant', 'edge', 'symmetric', 'reflect', and 'wrap'.
- cval (optional): Used with the 'constant' mode to set the value outside the image boundaries.
- clip (optional): Specifies whether to clip the output to the range of values in the input image. Enabled by default for higher-order interpolation methods.
- preserve_range (optional): Determines whether to maintain the original value range. If False, the image is converted to float using the conventions of img_as_float.
- anti_aliasing (optional): Specifies whether to apply Gaussian filtering before downsampling to avoid aliasing artifacts. If not specified, it is set to True when downsampling an image whose data type is not boolean. It is set to False when using nearest neighbor interpolation (order == 0) with integer input data type.
- anti_aliasing_sigma (optional): The standard deviation for Gaussian filtering used when anti-aliasing. By default, this value is chosen as (s - 1) / 2, where s is the downsampling factor (s > 1). For the up-size case, s < 1, no anti-aliasing is performed prior to rescaling.
Return Value
It returns the resized version of the input image (NumPy array).
Example
The following example demonstrates how to use the skimage.transform.resize() to perform image resizing.
import numpy as np from skimage import io, transform import matplotlib.pyplot as plt # Load the input image image = io.imread('Images/Flower1.jpg') # Define the output shape to half the size of the original image output_shape = (image.shape[0] // 2, image.shape[1] // 2) # Resize the image resized_image = transform.resize(image, output_shape, anti_aliasing=True) # Display the original and resized image fig, axes = plt.subplots(1, 2, figsize=(10, 5)) axes[0].imshow(image) axes[0].set_title('Original Image with shape '+str(image.shape)) axes[1].imshow(resized_image) axes[1].set_title('Resized Image with shape '+str(resized_image.shape)) # Show the plot plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −

Using the skimage.transform.rescale() function
This function allows you to scale an N-dimensional image by a specified factor. It performs interpolation to either up-scale or down-scale the image.
Syntax
Following is the syntax of this method −
skimage.transform.rescale(image, scale, order=None, mode='reflect', cval=0, clip=True, preserve_range=False, anti_aliasing=None, anti_aliasing_sigma=None, *, channel_axis=None)
Parameters
- image: The input image you want to scale (an N-dimensional NumPy array).
- scale: The scale factors, which can be a single float or a tuple of floats (e.g., (rows, cols[, ][, dim])) to specify separate scale factors for each dimension.
- order (optional): The order of spline interpolation, ranging from 0 to 5. Default is 0 for boolean images and 1 for others.
- mode (optional): Determines how points outside the input image boundaries are filled. Options include 'constant', 'edge', 'symmetric', 'reflect', and 'wrap'.
- cval (optional): Used with the 'constant' mode to set the value outside the image boundaries.
- clip (optional): Specifies whether to clip the output to the range of values in the input image. Enabled by default for higher-order interpolation methods.
- preserve_range (optional): Determines whether to maintain the original value range. If False, the image is converted to float using the conventions of img_as_float.
- anti_aliasing (optional): Specifies whether to apply Gaussian filtering before down-scaling to avoid aliasing artifacts. Not applied if the input image's data type is boolean.
- anti_aliasing_sigma (optional): The standard deviation for Gaussian filtering. By default, it's chosen as (s - 1) / 2, where s is the down-scaling factor.
- channel_axis (optional): Indicates the axis of the array that corresponds to the image channels. Use None for grayscale (single-channel) images. This parameter was added in version 0.19 of scikit-image.
Return Value
It returns a scaled version of the input image (NumPy array).
Example
The following example demonstrates how to use the skimage.transform.rescale() to perform image rescaling on a gray scale image.
import numpy as np from skimage import io, transform import matplotlib.pyplot as plt # Load the input image as gray image image = io.imread('Images/Flower1.jpg', as_gray=True) # Define the scale factor scale_factor = 0.25 # Rescale the image rescaled_image = transform.rescale(image, scale_factor, anti_aliasing=True) # Display the original and rescaled image fig, axes = plt.subplots(1, 2, figsize=(10, 5)) axes[0].imshow(image) axes[0].set_title('Original Image with shape '+str(image.shape)) axes[1].imshow(rescaled_image) axes[1].set_title('Rescaled Image with shape '+str(rescaled_image.shape)) # Show the plot plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −

When you load a 2D color image using rescale, it doesn't recognize that you have passed a color image. Instead, it assumes the image is an array of shape (100, 100, 3), where the last axis contains the red, green, and blue channels.
As a result, when you rescale the image without specifying the channel_axis parameter, it rescales along all axes, resulting in a new shape of (25, 25, 1) i.e, a grayscale image.
To avoid this issue and ensure that rescale works only across the rows and columns axes, without affecting the color channels, you should use the channel_axis parameter.
Example
The following example demonstrates how to use the skimage.transform.rescale() function on a color image to perform image rescaling operation.
import numpy as np from skimage import io, transform import matplotlib.pyplot as plt # Load the input image image = io.imread('Images/Flower1.jpg') # Define the scale factor scale_factor = 0.25 # Rescale the image rescaled_image = transform.rescale(image, scale_factor, anti_aliasing=True, channel_axis=2) # Display the original and rescaled image fig, axes = plt.subplots(1, 2, figsize=(10, 5)) axes[0].imshow(image) axes[0].set_title('Original Image with shape '+str(image.shape)) axes[1].imshow(rescaled_image) axes[1].set_title('Rescaled Image with shape '+str(rescaled_image.shape)) # Show the plot plt.tight_layout() plt.show()
Output
