composite distort with multiple images input.

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
alxgrh
Posts: 2
Joined: 2019-06-23T18:27:47-07:00
Authentication code: 1152

composite distort with multiple images input.

Post by alxgrh »

Hi,

I use Python's Wand interface. I'm trying to get an equivalent of the composite distort method as it's described here http://www.imagemagick.org/Usage/mappin ... se_distort .
The original convert program takes 3 images on input

Code: Select all

convert koala.gif  map_compress.gif map_compress_y.gif \
          -compose Distort  -define compose:args=37.5x37.5 -composite \
          distort_compose.gif
but the related Image.composite() function is able to process only two images at once. I tried to use double composite() call, but results weren't correct.

Is there a way to call compose distort from the Python code?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite distort with multiple images input.

Post by fmw42 »

You can combine the two displacement images as red and green and any blue image (typically all black) into one image. Then use that for your Wand two image displacement. See the note at the bottom of this section --- https://imagemagick.org/Usage/mapping/#displace_2d
alxgrh
Posts: 2
Joined: 2019-06-23T18:27:47-07:00
Authentication code: 1152

Re: composite distort with multiple images input.

Post by alxgrh »

Greatest thank you!

I got it working. Python equivalent of this command line follows

Code: Select all

convert ./image.png ./hgrad.png ./vgrad.png -gravity center -compose distort  -composite ./output.png

Code: Select all

from wand.image import Image

img = Image(filename='image.png')
hgrad = Image(filename='hgrad.png')
vgrad = Image(filename='vgrad.png')
blank = Image(width=img.width, height=img.height)

hgrad.composite(vgrad, operator='copy_green')
hgrad.composite(blank, operator='copy_blue')

img.composite(hgrad, operator='distort')
img.save(filename='output.png')
Post Reply