PIXELBANKv8.2.1
Menu

2D Scaling Matrix

Implement a 3×3 homogeneous transformation matrix for 2D scaling, a fundamental concept in 2D/3D Transformations. This transformation is crucial in Computer Vision as it allows images to be resized while maintaining their aspect ratio.

In 2D space, scaling is a linear transformation that enlarges or reduces objects by a certain factor. The scaling factors sxs_x and sys_y determine how much an object is stretched or shrunk along the xx and yy axes. To represent this transformation mathematically, we use a matrix equation.

To create the scaling matrix, follow these steps:

  1. Define the scaling factors sxs_x and sys_y.
  2. Construct a 3×3 matrix with sxs_x and sys_y on the diagonal.
(sx000sy0001)\begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{pmatrix}

This technique is widely used in image processing applications.

Example:

Input:
scaling_matrix(2, 3)
Output:
[[2,0,0],[0,3,0],[0,0,1]]
Reasoning:
  • The function is called with scaling factors sx=2s_x = 2 and sy=3s_y = 3: scaling_matrix(2, 3).
  • For 2D homogeneous scaling, we place sxs_x and sys_y on the main diagonal of a 3×33 \times 3 matrix, with 11 in the bottom-right:
    S=(sx000sy0001)S = \begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{pmatrix}.
  • Substituting sx=2s_x = 2, sy=3s_y = 3 gives
    S=(200030001)S = \begin{pmatrix} 2 & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 1 \end{pmatrix},
    which corresponds to [[2,0,0],[0,3,0],[0,0,1]].

Constraints:

  • sx and sy are positive floating-point numbers
Editor

Test Results

0/0
Run code to see test results.