Page 1 of 1

composite distort with multiple images input.

Posted: 2019-06-23T19:09:21-07:00
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?

Re: composite distort with multiple images input.

Posted: 2019-06-23T20:35:10-07:00
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

Re: composite distort with multiple images input.

Posted: 2019-06-24T01:22:25-07:00
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')