I need to shear and skew some images using python. I've come across this skimage module but I don't seem able to understand exactly how I'm supposed to use this.
I've tried a few things, which obviously gave me errors, because as I suddenly realized later, I'm not passing in my image to the function. I then noticed that the function doesn't take my image as an input parameter in the first place. So how should the transformation be applied? Or is this even the right function to be looking at in order to skew or shear an image?
The shear() function is an inbuilt function in the Python Wand ImageMagick library which is used to slide one edge of an image along the X or Y axis to create a parallelogram. The X-direction shear slides an edge along the X-axis, while a Y direction shear slides an edge along the Y-axis.
Shear tool is used to shift one part of an image, a layer, a selection or a path to a direction and the other part to the opposite direction. For instance, a horizontal shearing will shift the upper part to the right and the lower part to the left.
If you want to use the skimage module the order of operations are:
A work flow might look like the following:
from skimage import io
from skimage import transform as tf
# Load the image as a matrix
image = io.imread("/path/to/your/image.jpg")
# Create Afine transform
afine_tf = tf.AffineTransform(shear=0.2)
# Apply transform to image data
modified = tf.warp(image, inverse_map=afine_tf)
# Display the result
io.imshow(modified)
io.show()
The AffineTransform
class from the skimage module accepts a transformation matrix as its first parameter (which the class constructs if you instead use the other parameters).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With