Wand affine distort() function in Python

Affine destrortion method performs shear operation to the image. Arguments are similar to perspective destortion method, but only need a pair of 3 points and 12 Real numbers in the manner shown below:

src1x, src1y, dst1x, dst1y,
src2x, src2y, dst2x, dst2y,
src3x, src3y, dst3x, dst3y

Syntax: wand.image.distort(‘affine’, arguments)

Input Image:

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import Color from wand.color module
from wand.color import Color
# Import Image from wand.image module
from wand.image import Image
  
  
with Image(filename ='gog.png') as img:
    img.resize(140, 92)
    img.background_color = Color('skyblue')
    img.virtual_pixel = 'background'
    args = (
        10, 10, 15, 15# Point 1: (10, 10) => (15,  15)
        139, 0, 100, 20, # Point 2: (139, 0) => (100, 20)
        0, 92, 50, 80    # Point 3: (0,  92) => (50,  80)
    )
    # affline distortion using distort function
    img.distort('affine', args)
    img.save(filename ="afflinegfg.png")

chevron_right


Output:



Example #2:
changing argument values.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import Color from wand.color module
from wand.color import Color
# Import Image from wand.image module
from wand.image import Image
  
with Image(filename ='gog.png') as img:
    img.resize(140, 92)
    img.background_color = Color('skyblue')
    img.virtual_pixel = 'background'
    args = (
        20, 21, 12, 11# Point 1: (10, 10) => (15,  15)
        38, 1, 17, 0, # Point 2: (139, 0) => (100, 20)
        7, 92, 50, 80    # Point 3: (0,  92) => (50,  80)
    )
    # affline distortion using distort function
    img.distort('affine', args)
    img.save(filename ="afflinegfg2.png")

chevron_right


Output:

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.




My Personal Notes arrow_drop_up

Hi there I am a student of CGC COE, Landran in CSE department and have a great interest in programming

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.