Page 1 of 1

De polar problems

Posted: 2013-07-01T07:40:46-07:00
by bayley
Hi, i'm a bit new to image magic, I'm hoping to convert some conic projection maps roughly to a cyclindrical projection.
It's 8207x6062, i've calculated the centre of the cone net to be at 4412,96810. Obviously this is outside the canvas areas. The left side map is about 14* lognitude from the right side. SO this is why as you can see i put in -7,7 for the start and finish angle.

So far it just WONT work. i get a narrow picture iwth nothing usefull.

Can someone help?

I think i'm misunderstanding the use of the parameters?

I also tried using shepherd distort but this doesn't work and is not approriate due to the inverse square relationship it uses to determine control points affect on pixels.


Below is the command i have been using and the input image i'm using

Code: Select all

input_map.jpg -distort DePolar "96661.8,91637.7,7077,96810.5,-7,7" test_depolar.jpg
Image

Re: De polar problems

Posted: 2013-07-01T10:15:22-07:00
by fmw42
The arguments are

Radius_Max Radius_Min Center_X,Center_Y Start_Angle,End_Angle

Radius_MIn should be zero relative to the center coordinates. Radius_Max probably should correspond to the distance from the center to the larger side of the image relative to the center.

But I am not sure I really understand your image that well. Is it a full conic or a section of a conic? If the latter then I am not sure how to treat that in the depolar sense. Try using +depolar and see if that helps.

If it is a small arc on the conic (like in the inset diagram), perhaps the best way is to just use BilinearForward and straighten the sides to a rectangle using the four corners of the conic arc.

Re: De polar problems

Posted: 2013-07-01T20:09:47-07:00
by bayley
Its just a small arc of the conic section, it neither extends to the apex not to the the full circumfrence of the circle. Yes, thats what i use using my arguments, however i assumed that min radius would be the smallest radius to the centre that is indside the canvas. But in anycase I was playing arround with the order of magnitude of the argumes, ie 0 then 1 then 9 then 90,900, etc etc.

I'm unfamiliar with bi-linear, but i will give it a shot.

Re: De polar problems

Posted: 2013-07-01T20:30:43-07:00
by fmw42
actually to undistort the image it would bilinearreverse

see http://www.imagemagick.org/Usage/distor ... ar_reverse

Perhaps Anthony can suggest the proper arguments to use depolar.

Re: De polar problems

Posted: 2013-07-01T22:51:17-07:00
by anthony
This may be tricky. De-polar was designed specifically to reverse a polar distorted image.

You know where the center is, but you will need to specify the angles and radius in which your map lies relative to that center.
The angles, and radius is what is then maped into the sides and top/bottom edges of the final image.

Okay image is 1600x1182 pixels. the center is at 4412,96810

So mapping the four corners into an angle

Code: Select all

 corner    --> relative to center  -> radius      angle
  0,0                -4412,-96810        96910
 1600,1182      -2812,-95628         95668
0,1182             -4412,-95628                       -177.36
1600,0             -2812,-96810                       -178.33
convert input_map.jpg +distort Depolar '96910 95668 4412,96810 -178.33 -177.36' +repage show:

Which is again very long and thin. Expanding the angles to -200 to -100 produces a more square output, but it is blank.

Adding verbose should let use see the reverse mapping, whcih should be mapping destination image pixels into angle,radius, and mapping that to source image lookups.

Code: Select all

convert input_map.jpg -verbose +distort Depolar '96910 95668 4412,96810 -200 -100' +repage show:
DePolar Distort, Internal Coefficents
  c0 = +96910.000000
  c1 = +95668.000000
  c2 = +4412.000000
  c3 = +96810.000000
  c4 = -3.490659
  c5 = -1.745329
  c6 = +0.001610
  c7 = +1.000000
DePolar Distort, FX Equivelent:
  -size 1084x1242 -page +0+0 xc: +insert \
  -fx 'aa=(i+.5)*0.001610 +3.490659;
       rr=(j+.5)*1.000000 +95668.000000;
       xx=rr*sin(aa) +4412.000000;
       yy=rr*cos(aa) +96810.000000;
       v.p{xx-.5,yy-.5}' \
FYI the 'c' values are the coefficents the user input arguments are converted into
c0,c1 radius for Y coodinate C0 only used for determining +distort image bounds
c2,c3 center of polar plot (in mathematical coodinates perhaps it you need +0.5 for center of a pixel?
c4,c5 given angles in radians
c6,c7 increment and scaling for pixel coordinates to angle,radius respectively.

I am not certain what is wrong with the scaling of angle to (X in destination image), whcih is the c6 coefficent.


The white (border edges of the original image) seems to indicate that the above calculation is missing the original image (only producing virtual pixels). Adding -virtual-pixel tile shows it is doing something but it is not what is expected (actually the result is a rather lovely 'wood grain' type pattern!!!!

Code: Select all

convert input_map.jpg -virtual-pixel tile +distort Depolar '96910 95668 4412,96810 -200 -100' +repage show:
As such I think I have the angles wrong... Looking in quadrants... okay found the map in the third quadrant -- whcih is close
but not exactly where I thought the image should have been! (my angle calculation was off)

Code: Select all

convert input_map.jpg -virtual-pixel gray +distort Depolar '96910 95668 4412,96810 -180 -170' +repage -scale 80% show:
verbose...

Code: Select all

DePolar Distort, Internal Coefficents
  c0 = +96910.000000
  c1 = +95668.000000
  c2 = +4412.000000
  c3 = +96810.000000
  c4 = -3.141593
  c5 = -2.967060
  c6 = +0.001601
  c7 = +1.000000
DePolar Distort, FX Equivelent:
  -size 109x1242 -page +0+0 xc: +insert \
  -fx 'aa=(i+.5)*0.001601 +3.141593;
       rr=(j+.5)*1.000000 +95668.000000;
       xx=rr*sin(aa) +4412.000000;
       yy=rr*cos(aa) +96810.000000;
       v.p{xx-.5,yy-.5}' \
The FX equivelent version generates the same image!

Code: Select all

convert input_map.jpg -virtual-pixel gray \
  -size 109x1242 -page +0+0 xc: +insert \
   -fx 'aa=(i+.5)*0.001601 +3.141593;
      rr=(j+.5)*1.000000 +95668.000000;
      xx=rr*sin(aa) +4412.000000;
      yy=rr*cos(aa) +96810.000000;
      v.p{xx-.5,yy-.5}' \
   show:
But the calculated viewport image is very badly distorted. That seems to indicate something about converting the angle range for that radius is going badly wrong. Probably it using angle* half maximum radius, rather than angle*(max-min_radius)/2

The height (radius difference) is right, just width (angle) calculation, (angle per X pixel step))

I really can not see what is wrong..
c6 calculation is...

Code: Select all

coeff[6]=(coeff[5]-coeff[4])/geometry.width
where geometry.width is the calculated width for the output image.

that width is...
geometry.width = (size_t)
ceil((coeff[0]-coeff[1])*(coeff[5]-coeff[4])*0.5);
or radius_average * angle_difference

or (96910-95668)/2 * ((-2.967060)-(-3.141593)) => 108.3 => 109 pixels.

Everything seem right, So I really can't see why it is wrong.

Re: De polar problems

Posted: 2013-07-02T00:02:35-07:00
by bayley
Ok, next best thing would be some sort of linear shepherd distortion. Does anyone know how to use a shepherd distort that uses linear interpolation instead of invers square? still looking into bi-linear.

Re: De polar problems

Posted: 2013-07-02T21:28:31-07:00
by anthony
Shepards Distiortion, like Shepards Sparse Coloring (they actually share code), can be controlled using the define 'shepards:power'

See IM Examples, Distorts, Shepard's Power Factor
http://www.imagemagick.org/Usage/distor ... ards_power

However while Shepard's Distortion is completely free form, it has the problem in that it does not handle rotations near the control points. The result is swirls and curves in the distorted image.
Shepards and Image Rotations
http://www.imagemagick.org/Usage/distor ... s_rotation


One alternative that is often used by map makers is Polynomial. It is not a free form (due to number of control points), but it allows you to map an array of points in a global fashion from one source to another, with rotations.

Distorts, Polynomial Distortion (distorts using a polynomial fit)
http://www.imagemagick.org/Usage/distorts/#polynomial