I plan to flatten an images on curved surface(eg: jar or door knob) and I found a pretty good post which helps me a lot :)(link below). However, I still confuse on how to map image coordinate to cylindrical coordinate. Help needed on explanation. Or any other simple algorithm that I can use for mapping? Thanks in advance.

How to peel the labels from marmalade jars using Mathematica?

arcSinSeries = Normal[Series[ArcSin[α], {α, 0, 10}]]
mapping[{x_, y_}] := 
c1 + c2*(arcSinSeries /. α -> (x - cx)/r) + c3*y + c4*x*y, 
top + y*height + tilt1*Sqrt[Clip[r^2 - (x - cx)^2, {0.01, ∞}]] + 
tilt2*y*Sqrt[Clip[r^2 - (x - cx)^2, {0.01, ∞}]]
  • 2
    $\begingroup$ I think you may find this question helpful: QR Code in shopping cart handle $\endgroup$
    – MarcoB
    May 25, 2015 at 8:04
  • $\begingroup$ @MarcoB Thanks :) That really helps. $\endgroup$
    – Chong Vera
    May 25, 2015 at 16:43

1 Answer 1


Here's how I arrived at this (admittedly, quite ugly) mapping function: The "right" function to map points from cylinder coordinates to image coordinates in a pinhole camera model is the one MarcoB linked to in his comment. In a nutshell:

  • {Sin[u],Cos[u],v,1} converts from cylinder coordinates u,v to (homogeneous) 3d coordinates
  • which you then multiply by the camera projection matrix
  • and use Most[#]/Last[#]& to convert from homogeneous coordinates to 2d euclidean coordinates.

The projection matrix contains several degrees of freedom (for camera position, orientation, "zoom" and so on). If you know the values for these, you can use that formula to project from the cylinder to the image, or solve for $u$ and $v$ and project from image coordinates to cylinder coordinates.

In the "marmalade jars" answer, however, I don't know these degrees of freedom, and instead tried to estimate them using FindMinimum, and that's where I ran into problems:

  • estimating some values (especially zoom vs. camera distance) given just the label's outline is ill-conditioned.
  • and the inverse mapping from image coordinates to cylinder coordinates contains inverse trigonometric functions, and FindMinimum kept aborting because the mapping returned complex numbers.

To work around these problems, I've come up with the mapping function you posted, which is an ad hoc approximation for vertical cylinders with no perspective distortion. With the added bonus that it's free of trigonometric functions and always returns real values.

  • $\begingroup$ May I know how you derive the approximation for vertical cylinder? Is it using parabolic equation? thanks. $\endgroup$
    – Chong Vera
    May 25, 2015 at 16:48
  • $\begingroup$ @ChongVera: IIRC, I started with a simple 2nd order polynomial in X direction and 1st order polynomial in Y direction. Then I kept adding terms that didn't break FindMinimum and seemed to improve the result image visually. So, basically, by trial and error. $\endgroup$ May 25, 2015 at 18:00
  • $\begingroup$ Thank you so much, look like I have found the right expert. :) Appreciate if you able to share the how do you able to get the Y direction especially 'tilt1*Sqrt[r^2 - (x - cx)^2 + tilt2*y*Sqrt[r^2 - (x - cx)^2]'. I've been thinking about this but cannot get any clue yet. $\endgroup$
    – Chong Vera
    May 27, 2015 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.