Distort or trapezoid transformation

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
mickpr
Posts: 5
Joined: 2017-01-05T15:43:43-07:00
Authentication code: 1151

Distort or trapezoid transformation

Post by mickpr »

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.
Thanks in advance!
Mike
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort or trapezoid transformation

Post by snibgo »

MagickShearImage() ?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distort or trapezoid transformation

Post by fmw42 »

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.
mickpr
Posts: 5
Joined: 2017-01-05T15:43:43-07:00
Authentication code: 1151

Re: Distort or trapezoid transformation

Post by mickpr »

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".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort or trapezoid transformation

Post by snibgo »

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().
snibgo's IM pages: im.snibgo.com
mickpr
Posts: 5
Joined: 2017-01-05T15:43:43-07:00
Authentication code: 1151

Re: Distort or trapezoid transformation

Post by mickpr »

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)!
https://mateuxteknisk.systime.dk/filead ... 7b4b6f.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distort or trapezoid transformation

Post by fmw42 »

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort or trapezoid transformation

Post by snibgo »

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.

See also http://www.imagemagick.org/script/comma ... hp#distort , the "Perspective" text.
snibgo's IM pages: im.snibgo.com
mickpr
Posts: 5
Joined: 2017-01-05T15:43:43-07:00
Authentication code: 1151

Re: Distort or trapezoid transformation

Post by mickpr »

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.
:(
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort or trapezoid transformation

Post by snibgo »

What version of IM? In 6.9.3-8, "distort" is in Magick++\Image.h
snibgo's IM pages: im.snibgo.com
mickpr
Posts: 5
Joined: 2017-01-05T15:43:43-07:00
Authentication code: 1151

Re: Distort or trapezoid transformation

Post by mickpr »

Magic++ 8:6.8.9.9-7ubuntu5.3
..
Now I see it. thank you.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Distort or trapezoid transformation

Post by dlemstra »

Thats really odd 'distort' has been available in Magick++\Image.h for ages. It has been added before your version was released in 2014.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
lq634254672
Posts: 5
Joined: 2018-07-06T21:08:17-07:00
Authentication code: 1152

Re: Distort or trapezoid transformation

Post by lq634254672 »

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.

See also http://www.imagemagick.org/script/comma ... hp#distort , the "Perspective" text.
How do you know to set "distort:viewport=WxH" for distort function?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort or trapezoid transformation

Post by snibgo »

snibgo's IM pages: im.snibgo.com
Post Reply