I am trying to use PythonMagickWand to use a Shepards distortion on an image. You can also see the source of distort.c that is used by ImageMagick.

PythonMagickWand does not by default support Shepards distortion. To fix this, I added in:

ShepardsDistortion = DistortImageMethod(15)

to line 544 of PythonMagickWand (See here for my modified PythonMagicWand). The 15 pointer is in reference to distort.h (line 51) of the MagickWand source in which ShepardsDistortion is the 15th item on the list. This fits with all of the other supported distortion methods.

Now, something that I may be doing wrong is presuming that the existing distortion methods that are supported by PythonMagickWand use the same type of arguments as the Shepards. They might not but I do not know how I can tell. I know that distort.c is doing the work, but I can't work out if the arguments it takes in are the same or different.

I have the following code (snippet):

from PythonMagickWand import * from ctypes import * arrayType = c_double * 8 pointsNew = arrayType() pointsNew[0] = c_double(eyeLeft[0]) pointsNew[1] = c_double(eyeLeft[1]) pointsNew[2] = c_double(eyeLeftDest[0]) pointsNew[3] = c_double(eyeLeftDest[1]) pointsNew[4] = c_double(eyeRight[0]) pointsNew[5] = c_double(eyeRight[1]) pointsNew[6] = c_double(eyeRightDest[0]) pointsNew[7] = c_double(eyeRightDest[1]) MagickWandGenesis() wand = NewMagickWand() MagickReadImage(wand,path_to_image+'image_mod.jpg') MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False) MagickWriteImage(wand,path_to_image+'image_mod22.jpg')

I get the following error:

MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False) ctypes.ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected LP_c_double instance instead of list

I am aware that pointsNew is the wrong way of providing the arguments.. But I just don't know what is the right format. This is an example distort command that works when run in Terminal:

convert image.jpg -virtual-pixel Black -distort Shepards 121.523809524,317.79638009 141,275 346.158730159,312.628959276 319,275 239.365079365,421.14479638 232,376 158.349206349,483.153846154 165,455 313.015873016,483.153846154 300,455 0,0 0,0 0,571.0 0,571.0 464.0,571.0 464.0,571.0 0,571.0 0,571.0 image_out.jpg

So I guess the question is: How do I create a list of c_doubles that will be accepted by PythonMagickWand? Or is my hack to add Shepards Distortion into PythonMagickWand completely wrong?

I basically need to re-create the terminal command. I have got it working by using subprocess to run the command from Python but that is not how I want to do it.