Skip to content
Related Articles

Related Articles

Improve Article

Python – distort() method in Wand

  • Last Updated : 20 Jul, 2021
Geek Week

ImageMagick provides several ways to distort an image by applying various transformations against user-supplied arguments. In Wand, the method distort() is used, and follows a basic function.
 

Syntax : 
 

wand.image.distort(method, arguments, best_fit)

Parameters : 
 

ParameterInput TypeDescription
methodbasestringBlack point, as a percentage of the system’s quantum range. Defaults to 0..
argumentscollections.abc.SequenceDistortion method name from DISTORTION_METHODS.
best_fitboolAttempt to resize resulting image fit distortion. Defaults False. 
 

Following are the Distortion Methods : 
 

Distortion MethodDescription
‘undefined’default Distrortion Method
‘affine’parallel type of destortion.
‘affine_projection’kind of 3 parallelogram projection.
‘scale_rotate_translate’transformation distortion
‘perspective’3 dimensional outwards projection distortion.
‘perspective_projection’creates a away perspective.
‘bilinear_forward’based on bilinear equation.
‘bilinear_reverse’based on reverse bilinear equation.
‘polynomial’based on polynomial.
‘arc’creates a circular curve of image.
‘polar’creates a polar distortion effect.
‘depolar’creates a depolar distortion effect.
‘cylinder_2_plane’creates a cylinder to plane distortion effect.
‘plane_2_cylinder’creates a plane to cylinder distortion effect.
‘barrel’creates outwards bump on 2d image.
‘barrel_inverse’creates inwards bump on 2d image.
‘resize’resize destortion image.
‘sentinel’creates sentinel image distortion.

Source Image: 
 



Code Example 1: 
 

Python3




# Import Image from wand.image module
from wand.image import Image
  
# Read image using Image function
with Image(filename ="gog.png") as img:
    img.distort('arc', (45, ))
    img.save(filename ='gogdistort1.png')

Output Image: 
 

Code Example 2: 
Changing DISTORTION_METHOD to ‘perspective’. 
 

Python3




# Import Image from wand.image module
from wand.image import Image
  
# Read image using Image function
with Image(filename ="gog.png") as img:
    arguments = (0, 0, 20, 60,
                 90, 0, 70, 63,
                 0, 90, 5, 83,
                 90, 90, 85, 88)
    img.distort('perspective', arguments)
    img.save(filename ='gogdistort.png')

Output Image: 
 

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :