Page 1 of 1

### Distort or trapezoid transformation

Posted: 2017-01-05T15:50:42-07:00
Hi
I've a problem with Magick++ (c++) where is no distort function implemented.
I
use Ubuntu 16.04 with libmagick++ Q16 12.0.1.
Do you have any solution of this problem?

I'm trying to make left and right oblate image from the stright rectangular image.
Mike

### Re: Distort or trapezoid transformation

Posted: 2017-01-05T16:03:24-07:00
MagickShearImage() ?

### Re: Distort or trapezoid transformation

Posted: 2017-01-05T17:58:41-07:00
See distort (perspective or bilinear) or affineTransform at http://www.imagemagick.org/Magick++/Ima ... %20Methods. Sorry I do not know Magick++ or any more details.

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T02:17:06-07:00
Thanks for answers. But they didn't solve my problem.

In ruby language I've been doing trapezoid distortion for example in that way:

points = [1.5, 0,0, 0,squeeze, width,0, width,squeeze, width,height, width,height - squeeze, 0,height, 0,height-squeeze]
img_left = img_left.distort(Magick::PolynomialDistortion, points)

I just want to make it in C++ (with Magick++ library), but apart of that there IS "distort" function in http://www.imagemagick.org/Magick++/Ima ... %20Methods ... there is no such function in real life in library: libMagick++ (libGraphicsMagick++).

In the last case I'll make this function from sources myself, but I don't want to re-invent wheel again - if there is any simple solution. to make "trapezoid distortion".

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T08:49:06-07:00
Perhaps perspective distort does what you want. You can give this four coordinates of an image, and the four new coordinates for those points, and the image will be distorted.

See magick-image.c function MagickDistortImage().

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T12:06:36-07:00
snibgo wrote:Perhaps perspective distort does what you want.
You can give this four coordinates of an image, and the four new coordinates for those points, and the image will be distorted.

See magick-image.c function MagickDistortImage().
Could you say something more precise?
I can't go to C from C++, there is too much job already done in my project to do this.

What I want is this:
https://www.regneregler.dk/g_images/lig ... z-1317.png
not this (not Shear)!

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T12:24:04-07:00
If you can find the details of distort perspective in Magick++, it will allow you to pick 4 arbitrary points on each image such that you can warp a rectangle into a trapezoid. See http://www.imagemagick.org/Usage/distorts/#perspective

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T12:26:57-07:00
With C++, use Image.cpp:
void Magick::Image::distort(const DistortImageMethod method_,
const size_t number_arguments_,const double *arguments_,const bool bestfit_)
With the PerspectiveDistortion method, give 4 input coordinate as the corners of your image, and output coordinate as the places you want them to move to.

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T14:43:42-07:00
There is no distort function in Magick++ library at all!
I scan all of *.h files, and tried different version of this library.
There are other transform functions, like shear for example or affine transform, but this will not help.
It looks, that I have to make distort function myself.
Such a pity.

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T14:51:08-07:00
What version of IM? In 6.9.3-8, "distort" is in Magick++\Image.h

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T15:22:52-07:00
Magic++ 8:6.8.9.9-7ubuntu5.3
..
Now I see it. thank you.

### Re: Distort or trapezoid transformation

Posted: 2017-01-06T16:09:33-07:00
Thats really odd 'distort' has been available in Magick++\Image.h for ages. It has been added before your version was released in 2014.

### Re: Distort or trapezoid transformation

Posted: 2018-07-07T06:16:19-07:00
snibgo wrote:
2017-01-06T12:26:57-07:00
With C++, use Image.cpp:
void Magick::Image::distort(const DistortImageMethod method_,
const size_t number_arguments_,const double *arguments_,const bool bestfit_)
With the PerspectiveDistortion method, give 4 input coordinate as the corners of your image, and output coordinate as the places you want them to move to.