Skip to content
Advertisement

Pinch/bulge distortion using Python OpenCV

I want to apply a pinch/bulge filter on an image using Python OpenCV. The result should be some kind of this example:

https://pixijs.io/pixi-filters/tools/screenshots/dist/bulge-pinch.gif

I’ve read the following stackoverflow post that should be the correct formula for the filter: Formulas for Barrel/Pincushion distortion

But I’m struggling to implement this in Python OpenCV.

I’ve read about maps to apply filter on an image: Distortion effect using OpenCv-python

As for my understanding, the code could look something like this:

JavaScript

Is this the correct way to achieve the distortion presented in the example image? Any help regarding useful ressources or preferably examples are much appreciated.

Advertisement

Answer

After familiarizing myself with the ImageMagick source code, I’ve found a way to apply the formula for distortion. With the help of the OpenCV remap function, this is a way to distort an image:

JavaScript

This has the same effect as using the convert -implode function from ImageMagick.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement