Barrel distortion and crop don't chain as expected with conv

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
olearypa

Barrel distortion and crop don't chain as expected with conv

Post by olearypa »

ImageMagick 6.4.4 2008-10-07 Q16 OpenMP (compiled from SRPM)
Linux 2.6.25.14-108.fc9.x86_64 #1 SMP x86_64
(same results with convert on Microsoft Windows XP SP2, official binary of ImageMagick 6.4.4 2008-10-05 Q16)

I have a series of images I am applying a barrel distortion to as a correction. To speed things up, I found the coefficients for a crop of the image--the only part I need--using PanoCoef, then tried to use:

Code: Select all

convert image.jpg -gravity Center -crop "800x600+0+0" -distort Barrel "-0.004817967 -0.010172833 -0.028159933 1.043146167" corrected-image.jpg
...but that didn't work correctly, giving a non-rectilinear output with a lot of stretching in the upper left corner. The same was true of the following Magick++ code which gives the same output:

Code: Select all

     const double distortParams[] = {-0.004817967, -0.010172833, -0.028159933, 1.043146167};
     image.read("image.jpg");
     image.crop(Magick::Geometry(800,600,239,211));
     image.distort(Magick::BarrelDistortion,4,distortParams);
     image.display();
However, adding a certain indirection suddenly makes the distort have the desired effect:

Code: Select all

convert image.jpg -gravity Center -crop "800x600+0+0" - | convert - -distort Barrel "-0.004817967 -0.010172833 -0.028159933 1.043146167" corrected-image.jpg
works as expected, as does:

Code: Select all

     const double distortParams[] = {-0.004817967, -0.010172833, -0.028159933, 1.043146167};
     image.read("image.jpg");
     image.chop(Magick::Geometry(239,211));
     image.crop(Magick::Geometry(800,600));
     image.distort(Magick::BarrelDistortion,4,distortParams);
     image.display();
Thanks,
Patrick
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Barrel distortion and crop don't chain as expected with conv

Post by fmw42 »

after -crop you need to add +repage

see http://www.imagemagick.org/Usage/crop/#crop_repage
olearypa

Re: Barrel distortion and crop don't chain as expected with conv

Post by olearypa »

D'oh. That's less than obvious. Still doesn't explain the difference between the Magick++ chop/crop vs. crop only, though, since the class docs mention nothing about the canvas geometry being affected by either command (and there appears to be no direct analog to +repage; Image::page requires that the Geometry be known a priori). Either way, what I have in the C++ code works, so no worries.

Thanks,
Patrick
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Barrel distortion and crop don't chain as expected with conv

Post by magick »

+repage is the same as setting the page geometry to 0x0+0+0.
Post Reply