Scikit Image - Polynomial Transform



A polynomial transform is a mathematical function that maps points from one coordinate space to another using a polynomial equation. It is a type of geometric transformation that is commonly used in various fields, including mathematics, physics, computer graphics, image processing, and computer vision.

The general form of a 2D polynomial transformation is as follows −

X = sum[j=0:order]( sum[i=0:j]( a_ji * x**(j - i) * y**i ))
Y = sum[j=0:order]( sum[i=0:j]( b_ji * x**(j - i) * y**i ))

Where x and y are the input coordinates, and a_ji and b_ji are the coefficients of the polynomial terms.

The Scikit-image library in Python provides a class called PolynomialTransform() to perform this geometric transformation on images.

Using the skimage.transform.PolynomialTransform() class

The skimage.transform.PolynomialTransform class is used for 2D polynomial transformations.

Syntax

Following is the syntax of this class −

class skimage.transform.PolynomialTransform(params=None, *, dimensionality=2)

Parameters

  • Params: The transformation is defined by a set of polynomial coefficients, which are organized in a (2, N) array. N * 2 = (order + 1) * (order + 2). The a_ji coefficients are stored in params[0, :], and the b_ji coefficients are stored in params[1, :].
  • Dimensionality: The dimensionality parameter specifies that it's a 2D transformation.

Example

The following example demonstrates how to use the transform.PolynomialTransform() class to apply the polynomial transformations between sets of corresponding points on an image.

import numpy as np
from skimage.transform import PolynomialTransform
import matplotlib.pyplot as plt
from skimage import io

# Load the input image
image = io.imread('Images/butterfly.jpg')

# estimate transformation parameters
src = np.array([10, 100, 300, 300]).reshape((2, 2))
dst = np.array([50, 10, 200, 200]).reshape((2, 2))

# Define the polynomial order
order = 2

# Estimate the polynomial transformation
tform = PolynomialTransform()
success = tform.estimate(src, dst, order)

# Apply the transformation using the warp function
warped = warp(image, tform)

# Display the original and transformed images
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].axis('off')

axes[1].imshow(warped, cmap='gray')
axes[1].set_title('Polynomial Transformed Image')
axes[1].axis('off')

plt.tight_layout()
plt.show() 

Output

On executing the above program, you will get the following output −

Advertisements