This article is focussed on illustrating the steps required in performing an image Shear Transformation. All of the concepts explored have been implemented by means of raw pixel data processing, no conventional drawing methods, such as GDI, are required.
Rabbit: Shear X 0.4, Y 0.4
Sample Source Code
This article is accompanied by a sample source code Visual Studio project which is available for download here.
Using the Sample Application
This article features a Windows Forms based sample application which is included as part of the accompanying sample source code. The concepts explored in this article can be illustrated in a practical implementation using the sample application.
The sample application enables a user to load source/input images from the local file system when clicking the Load Image button. In addition users are also able to save output result images to the local file system by clicking the Save Image button.
Image Shear Transformations can be applied to either X or Y, or both X and Y pixel coordinates. When using the sample application the user has option of adjusting Shear factors, as indicated on the user interface by the numeric up/down controls labelled Shear X and Shear Y.
The following image is a screenshot of the Image Transform Shear Sample Application in action:
Rabbit: Shear X -0.5, Y -0.25
Image Shear Transformation
In plane geometry, a shear mapping is a linear map that displaces each point in fixed direction, by an amount proportional to its signed distance from a line that is parallel to that direction. This type of mapping is also called shear transformation, transvection, or just shearing
Horizontal Shear Algorithm
Vertical Shear Algorithm
The algorithm description:
- Shear(x) : The result of a horizontal Shear Transformation – The calculated X-Coordinate representing a Shear Transform.
- Shear(y) : The result of a vertical Shear Transformation – The calculated Y-Coordinate representing a Shear Transform.
- σ : The lower case version of the Greek alphabet letter Sigma – Represents the Shear Factor.
- x : The X-Coordinate originating from the source/input image – The horizontal coordinate value intended to be sheared.
- y : The Y-Coordinate originating from the source/input image – The vertical coordinate value intended to be sheared.
- H : Source image height in pixels.
- W : Source image width in pixels.
Note: When performing a Shear Transformation implementing both the horizontal and vertical planes each coordinate plane can be calculated using a different shearing factor.
The algorithms have been adapted in order to implement a middle pixel offset by means of subtracting the product of the related image plane boundary and the specified Shearing Factor, which will then be divided by a factor of two.
Rabbit: Shear X 1.0, Y 0.1
Implementing a Shear Transformation
The ShearXY extension method targets the Point structure. The algorithms discussed in the previous sections have been implemented in this function from a C# perspective. The definition as illustrated by the following code snippet:
Rabbit: Shear X 0.0, Y 0.5
The ShearImage extension method targets the Bitmap class. This method expects as parameter values a horizontal and a vertical shearing factor. Providing a shearing factor of zero results in no image shearing being implemented in the corresponding direction. The definition as follows:
Rabbit: Shear X 0.5, Y 0.0
This article features a number of sample images. All featured images have been licensed allowing for reproduction.
The sample images featuring the image of a Desert Cottontail Rabbit is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license and can be downloaded from Wikipedia. The original author is attributed as Larry D. Moore.
The sample images featuring the image of a Rabbit in Snow is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license and can be downloaded from Wikipedia. The original author is attributed as George Tuli.
The sample images featuring the image of a Mountain Cottontail Rabbit is in the public domain in the United States because it is a work prepared by an officer or employee of the United States Government as part of that person’s official duties under the terms of Title 17, Chapter 1, Section 105 of the US Code. The original image can be downloaded from Wikipedia.
Rabbit: Shear X 1.0, Y 0.0
Rabbit: Shear X 0.5, Y 0.1
Rabbit: Shear X -0.5, Y -0.25
Rabbit: Shear X -0.5, Y 0.0
Rabbit: Shear X 0.25, Y 0.0
Rabbit: Shear X 0.50, Y 0.0
Rabbit: Shear X 0.0, Y 0.5
Rabbit: Shear X 0.0, Y 0.25
Rabbit: Shear X 0.0, Y 1.0
Related Articles and Feedback
Feedback and questions are always encouraged. If you know of an alternative implementation or have ideas on a more efficient implementation please share in the comments section.
I’ve published a number of articles related to imaging and images of which you can find URL links here:
- C# How to: Image filtering by directly manipulating Pixel ARGB values
- C# How to: Image filtering implemented using a ColorMatrix
- C# How to: Blending Bitmap images using colour filters
- C# How to: Bitmap Colour Substitution implementing thresholds
- C# How to: Generating Icons from Images
- C# How to: Swapping Bitmap ARGB Colour Channels
- C# How to: Bitmap Pixel manipulation using LINQ Queries
- C# How to: Linq to Bitmaps – Partial Colour Inversion
- C# How to: Bitmap Colour Balance
- C# How to: Bi-tonal Bitmaps
- C# How to: Bitmap Colour Tint
- C# How to: Bitmap Colour Shading
- C# How to: Image Solarise
- C# How to: Image Contrast
- C# How to: Bitwise Bitmap Blending
- C# How to: Image Arithmetic
- C# How to: Image Convolution
- C# How to: Image Edge Detection
- C# How to: Difference Of Gaussians
- C# How to: Image Median Filter
- C# How to: Image Unsharp Mask
- C# How to: Image Colour Average
- C# How to: Image Erosion and Dilation
- C# How to: Morphological Edge Detection
- C# How to: Boolean Edge Detection
- C# How to: Gradient Based Edge Detection
- C# How to: Sharpen Edge Detection
- C# How to: Calculating Gaussian Kernels
- C# How to: Image Blur
- C# How to: Image Transform Rotate
- C# How to: Compass Edge Detection
- C# How to: Oil Painting and Cartoon Filter
- C# How to: Stained Glass Image Filter