Shear
Shift rows or columns of an image or a video frame by linearly varying offset
Libraries:
Computer Vision Toolbox /
Geometric Transformations
Description
The Shear block transforms an input image or a video frame by shifting the rows or columns. The block transforms the input image using either horizontal or vertical shear.
Horizontal shear linearly shifts the rows in the image by gradually increasing the offset from left to right or right to left.
Vertical shear linearly shifts the columns in the image by gradually increasing the offset from top to bottom or bottom to top.
Examples
Apply Vertical Shear Transformation to Image
Apply shear transformation to an input image in the vertical direction.
Ports
Input
Image — Input image or video
matrix | array
Input image or video, specified as an M-by-N matrix, M-by-N-by-T array, M-by-N-by-C array, or M-by-N-by-C-by-T array. T is the number of frames in a video or image sequence, and C is the number of color channels.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
S — Shear value
vector
Shear value, specified as a two-element vector of the form, [first
last]
.
To horizontally shear the image, the block shifts the pixels of the first and last rows using the
first
andlast
values, respectively, specified to the S port.To vertically shear the image, the block shifts the pixels of the first and last columns using the
first
andlast
values, respectively,specified to the S port.
Dependencies
To enable this port, set the Shear values source parameter
to Input port
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Output
Output — Transformed image or video
matrix | array
Transformed image or video, returned as a P-by-Q matrix, P-by-Q-by-T array, P-by-Q-by-C array, or P-by-Q-by-C-by-T array. T is the number of frames in a video or image sequence, and C is the number of color channels.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Parameters
Shear direction — Direction of transformation
Horizontal
(default) | Vertical
Specify the shear direction for the input image, as one of these options:
Horizontal
— Shifts the rows of the input image with a linearly varying offset. Specify the offset limits of the first and the last row using the Row/column shear values [first last] parameter.Vertical
— Shifts the columns of the input image with a linearly varying offset. Specify the offset limits of the first and the last column using the Row/column shear values [first last] parameter.
Output size after shear — Transformed image size
Full
(default) | Same as input image
Specify the size of the transformed image as, Full
or
Same as input image
.
Full
— The block outputs the entire sheared image.Same as input image
— The block outputs a matrix of the same size as the input image. In this case, the output image contains the top-left portion of the sheared image, as limited by the input image dimensions.
Shear values source — Source of shear value offset limits
Specify via dialog
(default) | Input port
Select the source of shear value offset limits from these options:
Specify via dialog
— Specify the shear value offset limits using the Row/column shear values [first last] parameter.Input port
— Specify the shear value offset limits using the S port.
Row/column shear values [first last] — Shear value offset limits
[0 3]
(default) | two-element vector
Specify the shear value offset limits as a two-element vector of the form
[first last
]. The first
and
last
values represent the number of pixels to shift the first and
last rows or columns of the input image, respectively.
For example, if you set the Shear direction parameter to
Horizontal
and specify the Row/column shear
values [first last] parameter value as [50 150]
, the
block shifts the top row of the input image 50 pixels to the right and the bottom row
150 pixels to the right. To move either row to the left, specify a negative value for
the corresponding element of Row/column shear values [first last]
parameter.
Similarly, if you set the Shear direction parameter to
Vertical
and specify the Row/column shear values
[first last] parameter value as [10 50]
, the block
shifts the furthest left column 10 pixels down and the furthest right column 50 pixels
down. To shift either column up, specify a negative value for the corresponding element
of Row/column shear values [first last] parameter.
Dependencies
To enable this parameter, set the Shear values source
parameter to Specify via dialog
.
Maximum shear value — Maximum row or column shear
20
(default) | scalar
Specify the maximum number of pixels to shear any row or column of the input image. The shear block uses this parameter to determine the size of the sheared image. If any input to the S port is greater than the absolute value of the Maximum shear value parameter, the shear block reduces the input value to the maximum shear value.
Dependencies
To enable this parameter, set the Shear values source
parameter to Input port
.
Background fill value — Intensity value of the background in transformed image
0
(default) | scalar | three-element vector
Specify the intensity value of the background of the transformed image as a scalar intensity value or a three-element vector representing an RGB triplet.
Interpolation method — Method for interpolating transformed pixel values
Bilinear
(default) | Nearest neighbor
| Bicubic
Specify the method by which to interpolate the pixel values of the sheared image, as one of these options:
Nearest neighbor
—The Shear block uses the value of 1 nearest pixel for the new pixel value.Bilinear
— The new pixel value is the weighted average of the 4 nearest pixel values.Bicubic
— The new pixel value is the weighted average of the 16 nearest pixel values.
The number of pixels the block considers for interpolation affects the complexity
and accuracy of the computation. The Nearest neighbor
interpolation, which uses the fewest pixels, is the most computationally efficient and
least accurate while the Bicubic
interpolation is the least
computationally efficient and the most accurate. For more information about the
interpolation methods and kernels, see the More About section and
the Create and Compare Resizing Interpolation Kernels example.
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
More About
Nearest Neighbor Interpolation
For nearest neighbor interpolation, the block uses nearby, translated, pixel values for the output pixel values.
For example, suppose this matrix, represents your input image,
and you want to translate this image 1.7 pixels in the positive horizontal direction using nearest neighbor interpolation. These steps illustrate the nearest neighbor interpolation algorithm followed by the block:
Zero pad the input matrix and translate it 1.7 pixels to the right.
Create the output matrix by replacing each input pixel value with the translated value nearest to it resulting in this matrix:
Note
Despite specifying a value of 1.7 pixels to translate the image, this method translates the image by 2 pixels. Nearest neighbor interpolation is computationally efficient, but not as accurate as the bilinear and bicubic interpolation methods.
Bilinear Interpolation
For bilinear interpolation, the block uses the weighted average of two translated pixel values for each output pixel value.
For example, suppose this matrix, represents your input image,
and you want to translate this image by 0.5 pixels in the positive horizontal direction using bilinear interpolation. These steps illustrate the bilinear interpolation algorithm followed by the block:
Zero pad the input matrix and translate it 0.5 pixels to the right.
Create the output matrix by replacing each input pixel value with the weighted average of the translated pixel values on either side of the input pixel. The result is this matrix which has one column more than the input matrix.
Bicubic Interpolation
For bicubic interpolation, the block uses the weighted average of four translated pixel values for each output pixel value.
For example, suppose this matrix, represents your input image,
and you want to translate this image by 0.5 pixels in the positive horizontal direction using bicubic interpolation. These steps illustrate the bicubic interpolation algorithm followed by the block:
Zero pad the input matrix and translate it by 0.5 pixels to the right.
Create the output matrix by replacing each input pixel value with the weighted average of the two translated values on either side. The result is this matrix which has one column more than the input matrix:
Algorithms
Affine Transformation
Affine image transformation includes operations such as scaling, translation, shear, and rotation. The affine transformation matrix is a 3-by-3 matrix of the form .
Consider an input image with r rows and c columns. are pixel coordinates in the input image and are pixel coordinates in the transformed image. The relationship between the input and output pixel coordinates is defined by:
Shear transformation is an affine transformation that transforms the input image in the horizontal direction or vertical direction or both.
To obtain a horizontal shear transformation of an image, use the transformation matrix with a horizontal shear value, sh.
To obtain a vertical shear transformation of an image, use the transformation matrix with a vertical shear value, sv.
References
[1] Wolberg, George. Digital Image Warping. IEEE Computer Society Press Monograph. Los Alamitos, Calif: IEEE Computer Society Press, 1990.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)