Page 1 of 1

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

Posted: 2008-10-08T11:12:05-07:00
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

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

Posted: 2008-10-08T13:57:37-07:00
by fmw42
after -crop you need to add +repage

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

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

Posted: 2008-10-08T14:20:47-07:00
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

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

Posted: 2008-10-08T15:17:49-07:00
by magick
+repage is the same as setting the page geometry to 0x0+0+0.