bug in depolar

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
jfharper
Posts: 1
Joined: 2013-09-10T20:24:17-07:00
Authentication code: 6789

bug in depolar

Post by jfharper »

Following the discussion in viewtopic.php?f=1&t=23664 there appears to be a bug in the depolar code affecting the angular scale, in the current version 6.8.6-9. This is revealed in the verbose output, eg

Code: Select all

convert fc.png -verbose -distort DePolar "820 780, 893 269, 90, 180" show:
DePolar Distort, Internal Coefficents
  c0 = +820.000000
  c1 = +780.000000
  c2 = +893.000000
  c3 = +269.000000
  c4 = +1.570796
  c5 = +3.141593
  c6 = +0.002485
  c7 = +0.085470
DePolar Distort, FX Equivelent:
  -fx 'aa=(i+.5)*0.002485 -1.570796;
       rr=(j+.5)*0.085470 +780.000000;
       xx=rr*sin(aa) +893.000000;
       yy=rr*cos(aa) +269.000000;
       v.p{xx-.5,yy-.5}' \
coefficient c4 is the first angle in radians. In the fx equivalent code aa should run from the first angle (c4) to the second (c5) as i runs from 0 to the image width. But at i=0, aa=-c4, and at i=<image width> aa does not reach c5 (second angle), but rather some other odd value (c5-2*c4).
So the part of the image expected by computing the angles is not properly mapped. Changing the sign in the first expression to

Code: Select all

aa=(i+.5)*0.002485 +1.570796;
creates the expected output.
This fix can be applied to magick/distort.c at lines 2186 and 2581
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bug in depolar

Post by anthony »

Hmmmm yes that seems of glaringly wrong, in that the coefficient is simply the lower bound, and should be added. Just as it is for the radius coefficient. Really I don't know how I missed it before.

Also it is wrong in both in verbose FX equivalent and in actual distortion code, otherwise I would have picked it up in basic testing of the distortion (FX and true distort should come out pretty close)

The only reason it was not picked up is that Depolar is typically used in a polar-depolar cycle, which this bug does not effect (testing has confirmed this). It does explain a problem I was having with another user (who was using a center point far beyond image bounds).

Example testing...

From normal IM Examples...

Code: Select all

  convert worldmap_sm.jpg -virtual-pixel Black -background Black \
          +distort Polar  '60,20 0,0 -60,60' +repage polar_arc.jpg
Reverse (though aspect ratio and scaling is lost, which is understandable)

Code: Select all

  convert polar_arc.jpg -distort Depolar '60,20 61,61 -60,60' depolar_arc.jpg
Actually the +distort calculations for output image size could use some work.



This is the second time a negative has caused problems with distort (first time was blurry output from resampling)

This is actually one reason why the verbose FX equivalent is so useful. People can look at how the distortion actually works.

Also fixing for IMv7
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply