1

I have written the following GIMP script-fu function to remove lens distortion from an image using the lens-distortion-plugin. I execute this script through a command line function from my main python script. Just wondering if there is an equivalent ImageMagic function (or any other library) to achieve the same so that i don't have to leave the python script.

lens-distortion.scm

(define (lens-distortion filename destination)
  (let* (
    (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))  ; load the image
    (drawable (car (gimp-image-flatten image)))

    (offset-x -3.51)
    (offset-y -9.36)
    (main-adjust 28.07)
    (edge-adjust 0)
    (rescale -100)
    (brighten 0.58)
  )

  (gimp-message (string-append "processing-" filename))
  (plug-in-lens-distortion RUN-NONINTERACTIVE image drawable offset-x offset-y main-adjust edge-adjust rescale brighten)
  (gimp-file-save RUN-NONINTERACTIVE image drawable destination destination)
  (gimp-image-delete image)
 )
)

Example input image:

As you can see the distortion does not start from the middle which makes it a lot challenging to get rid of it.

enter image description here

DhiwaTdG
  • 748
  • 1
  • 10
  • 26
  • 1
    Can't tell about ImageMagick, but the lens-distortion plug-in in Gimp is now a façade for a GEGL filter, and GEGL filters 1) can be called from the command line, and 2) with GObject integration, can likely be called directly from Python. – xenoid May 12 '23 at 14:11
  • See my FFT tutorial and various distortion correction scripts for Imagemagick. See http://www.fmwconcepts.com/imagemagick/index.php and http://www.fmwconcepts.com/imagemagick/fourier_transforms/fourier.html. But in my experience they generally only work for more ideal cases. – fmw42 May 12 '23 at 15:13
  • @fmw42 Anything you've in your website is way above my knowledge of shell programming. I'll give it a go. I've just updated the script to include a sample image if that's of any help. – DhiwaTdG May 12 '23 at 15:30
  • That is barrel/pincushion distortion, not lens distortion as a blur. So my scripts won't deal with that except to add it, not remove it, unless you have the calibration already. But Imagemagick can correct or apply barrel/pincushion distortion. See the distortion page or my script pinbarrel. See also https://imagemagick.org/Usage/distorts/#barrel – fmw42 May 12 '23 at 16:41

0 Answers0