Image Shearing Digital Image Processing [21EC732]
INTRODUCTION
Image Shearing is a transformation technique in image processing that shifts the pixels
of an image along either the horizontal or vertical axis, creating a slanted or skewed effect. It
distorts the shape of the image by "sliding" rows or columns of pixels, giving the image a slanted
appearance.
Shearing is typically represented using transformation matrices, and it can be applied
horizontally (shifting pixels along the x-axis) or vertically (shifting pixels along the y-axis). This
technique is commonly used in graphics design, computer vision, and data augmentation for
tasks like creating artistic effects or correcting perspective distortions.
MATHEMATICAL EXPRESSION
Shearing changes(or deformed) the shape of the object. AS we are discussing 3D space so
shearing can also be done in any of the three directions as follows. Given below are the types
of shearing transformation.
Shearing in X-direction.
Shearing in y-direction
Shearing in z-direction.
Shearing in X-Direction: Here the coordinate of X remains unchanged while the coordinate of
Y and Z is changed. Shearing is done through the Shearing Transformation matrix, which is
represented as follows
Consider a point P[x, y, z] in 3D space over which we perform the shearing transformation in
the X-direction and it becomes P'[x, y,z].
Dept of ECE, VVIET, Mysuru Page 1
Image Shearing Digital Image Processing [21EC732]
Shearing in Y-Direction: Here the coordinate of Y remains unchanged while the coordinate of
X and Z are changed. Shearing is done through the Shearing Transformation matrix, which is
represented as follows.
Consider a point P[x, y, z] in 3D space over which we perform the shearing transformation in
the Y-direction and it becomes P'[x, y, z].
Shearing in Z-Direction: Here the coordinate of Z remains unchanged while the coordinate of
X and Y are changed. Shearing is done through the Shearing Transformation matrix, which is
represented as follows for the shearing in Z-direction.
Consider a point P[x, y, z] in 3D space over which we perform the shearing transformation in
the Z-direction and its become P'[x, y, z].
Dept of ECE, VVIET, Mysuru Page 2
Image Shearing Digital Image Processing [21EC732]
Here, xn, yn, zn Are showing=new values and x o, yo, zo Are showing=old values. Perform
Shearing Transformation in the given cuboid (OABCDEFG) along Z-direction if a shearing
parameter is as follows Sx=2, Sy=3. The Shearing transformation matrix for z-direction is as
follows.
Now, we’ll apply the shearing transformation condition over all the coordinates and calculate
the new corresponding coordinates: Point O[0, 0, 0] becomes O’ after performing Reflection
transformation:
Point A'[0, 0, 4] becomes A’ after performing Reflection
Dept of ECE, VVIET, Mysuru Page 3
Image Shearing Digital Image Processing [21EC732]
Point B'[0, 0, 4] becomes B’ after performing Reflection transformation:
Point C'[2, 4, 0] becomes C’ after performing Reflection transformation:
Point D'[2, 2, 4] becomes D’ after performing Reflection transformation:
Point E'[2, 0, 0] becomes E’ after performing Reflection transformation:
Dept of ECE, VVIET, Mysuru Page 4
Image Shearing Digital Image Processing [21EC732]
Point F'[ 0, 0, 2] becomes F’ after performing Reflection transformation:
Point G'[2, 0, 2] becomes G’ after performing Reflection transformation:
Finally, after performing the Shearing transformation on the given cuboid Figure will look like
as below:
Dept of ECE, VVIET, Mysuru Page 5
Image Shearing Digital Image Processing [21EC732]
PYTHON CODE FOR IMAGE SHEARING
import numpy as np
import cv2
import matplotlib.pyplot as plt
# read the input image
img = cv2.imread("city.jpg")
# convert from BGR to RGB so we can plot using matplotlib
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# disable x & y axis
plt.axis('off')
# show the image
plt.imshow(img)
plt.show()
# get the image shape
rows, cols, dim = img.shape
# transformation matrix for Shearing
# shearing applied to x-axis
M = np.float32([[1, 0.5, 0],
[0, 1 , 0],
[0, 0 , 1]])
# shearing applied to y-axis
# M = np.float32([[1, 0, 0],
# [0.5, 1, 0],
# [0, 0, 1]])
# apply a perspective transformation to the image
sheared_img = cv2.warpPerspective(img,M,(int(cols*1.5),int(rows*1.5)))
# disable x & y axis
plt.axis('off')
Dept of ECE, VVIET, Mysuru Page 6
Image Shearing Digital Image Processing [21EC732]
# show the resulting image
plt.imshow(sheared_img)
plt.show()
# save the resulting image to disk
plt.imsave("city_sheared.jpg", sheared_img)
OUTPUT :
Dept of ECE, VVIET, Mysuru Page 7