title: Mapping image from cartesian to polar coordinates with imageR
body: <p>I am attempting to map a panoramic image into polar coordinates using imageR, but get strange results.</p>
  <p>As an example, I would like to take a square panorama like this one (courtesy of <a href="http://www.flickr.com/photos/gadl/" rel="nofollow noreferrer">Flickr user gadl</a> (<a href="http://www.lrde.epita.fr/%7Eadl/" rel="nofollow noreferrer">Alexandre Duret-Lutz</a>) under CC BY-NC-SA and edited into a square):</p>
  <p><a href="https://i.stack.imgur.com/X322n.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X322n.jpg" alt="square panorama" /></a></p>
  <p>And remap it to something like this (which I've done in GIMP):</p>
  <p><a href="https://i.stack.imgur.com/6in7i.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6in7i.jpg" alt="polar coordinate remapping of square panorama" /></a></p>
  <p>I've gotten pretty close in imageR with this code:</p>
  <pre><code>library(imager)
  pano &lt;- mirror(load.image(&quot;pano_image.jpg&quot;), &quot;y&quot;) # mirroring the image to map to center
  map.shift &lt;- function(x,y) list(x = y*cos(x), y = y*sin(x)) # Here, y is the radius and x is theta
  polar_pano &lt;- imwarp(pano, map = map.shift)
  plot(polar_pano)
  </code></pre>
  <p>But I get the strange result:</p>
  <p><a href="https://i.stack.imgur.com/CRLjM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CRLjM.png" alt="imager output of polar coordinate mapped panorama" /></a></p>
  <p>I'm not sure why it is only mapping into one quadrant? (Note: I realize that the interpolation will be strange in this example--that is not the issue).
  To confirm that this <em>should</em> work, here is a toy example:</p>
  <pre><code>library(ggplot)
  test &lt;- data.frame(&quot;val&quot; = rep(100:1, each = 99), theta = rep(1:100, 99), r = rep(1:100, each = 99))
  ggplot(test, aes(x = theta, y = r, col = val)) + geom_point()
  
  # Now converting from polar to cartesian
  test$x &lt;- test$r*cos(test$theta)
  test$y &lt;- test$r*sin(teast$theta)
  ggplot(test_p2c, aes(x = x, y = y, col = val)) + geom_point()
  </code></pre>