Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:55:28+00:00 2026-05-15T07:55:28+00:00

I am trying to use PythonMagickWand to use a Shepards distortion on an image.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:55:28+00:00Added an answer on May 15, 2026 at 7:55 am

    From NeedMoreBeer on Reddit.com:

    from PythonMagickWand import *
    from ctypes import *
    
    arrayType = c_double * 8  
    pointsNew = arrayType()
    pointsNew[0] = c_double(121.523809524)
    pointsNew[1] = c_double(317.79638009)
    pointsNew[2] = c_double(141)
    pointsNew[3] = c_double(275) 
    pointsNew[4] = c_double(346.158730159)
    pointsNew[5] = c_double(312.628959276)
    pointsNew[6] = c_double(319)
    pointsNew[7] = c_double(275)
    
    ShepardsDistortion = DistortImageMethod(14)
    
    MagickWandGenesis()
    wand = NewMagickWand()
    MagickReadImage(wand,'/home/user/image.png')
    MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False)
    MagickWriteImage(wand,'/home/user/image_mod22.jpg')
    

    More specifically for me, it was the following line:

    ShepardsDistortion = DistortImageMethod(14)
    

    That fixed it for me! Thanks again to NeedMoreBeer from Reddit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to use ImageInfo and Jython to get information from a image on
I am trying use the jQuery table sorter plugin for a table that is
i'm trying use webview to load a image from sdcard i use this path
I have a regex that I'm trying use to validate against strings. Trying to
Trying to use pil for creating grid-like layout from images. But that code only
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
While trying to use LINQ to SQL I encountered several problems. I have table
I' trying to use a Linq query to find and set the selected value
I'm trying to use svnmerge.py to merge some files. Under the hood it uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.