Convert equirectangular panorama to cubic panorama automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Convert equirectangular panorama to cubic panorama automatically

    I need to know a way to convert an equirectangular spherical panorama image into a cubic panorama using C#.

    If you don't know what a cubic panorama is, look at this:

    Own this domain today. We make your shopping experience easy. Friendly and quick customer service.


    Then download the source image for what you're seeing:

    http://infectionist.com/images/halo_...h_Panorama.jpg (WARNING: 4.5MB, 4000x2000 resolution)

    I need to be able to do this on-the-fly from within the program. Here is my logic, which appears to be wrong:

    Equirect. panoramas must have a 2: aspect ratio, meaning the width must be exactly twice the height. Cubic panoramas are basically a flattened cube with all 6 faces arranged together so that if you formed a cube with the faces, they would fit together perfectly.

    Each face of a cubic panorama has exactly a 90°x90° field of view. My reasoning was that since an equirect panorama basically shows all 360° in the width and 180° in the height, that 90° should be exactly the WIDTH x (HEIGHT/2). I tried cropping my image to half height, then making it a square by scaling the height to 4000 pixels. Then I applied a Rectangular to Polar filter in Photoshop, which is supposed to correct my image, but leaves me with a circle on the outside where the pixels are stretched. I figured out the area of the square that would fit inside the circle (D = diameter; a = square side; a = sqrt(D^2/2);) and cropped out that portion...the problem is, while it's close to what I need, it's not exactly what I need, since the resulting parts still don't fit perfectly together.

    So, enough of my explanation of that, does anyone know how I might go about converting an equirectangular image to a cubic one in C#? I can't really finish my project if it can't be done.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I don't really know enough about this, but doesn't it appear as though the 4 sides remain the same, whereas the top and the bottom are stretched out into a rectangle with 8 times width as height?

    I think: Imagine the top square divided into 8 triangles, eg, with both diagonals, and folded in half topwise, and sidewise. Each of those triangles is converted into a square.

    I'm not sure, but I believe the transformation of a triangle is something like:
    Take the triangle scaled to (0,0), (1,0) and (0,1)
    (x,y) if x > y -> (1+y/x)(x,y)
    if y > x -> (1+x/y)(x,y)

    This produces a unit cube.

    The reverse transformation is something like:
    (x,y) -> if x > y -> (x,y) / (1 + y/x)
    if y > x (x,y) / (1 + x/y)

    Again, I could be totally wrong.

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      I don't think this is a C# thing, per se... it's a general algorithm thing. For myself, I have no idea how this is done... is there an algorithm for generating this on the web anywhere (ie, google)?

      I'd imagine those images you linked are generated from flat screenshots taken from the game (as you say, 90° FOV from 6 view angles to generate a cube map). So I guess what you're looking for is how to generate a sphere map from a cube map.

      I found these via google...

      This one talks about how to do it in OpenGL. There may be some DirectX or XNA equivalents as well.


      This one has a link to a tool that might be able to generate them for you (outside of C#). If it works but you need your program to do it, you might be able to do the conversion via command line and make your program call it.


      Good luck!

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        What I did to aquire that equirectangular image was set my camera up in a certain location in the game, then take screenshots while rotating the camera about 30 degrees between each one. I ended up with 113 screenshots at the end, and stitched them together using PTGui. The game only has a 70 degree field of view.

        I already looked at what my panorama would look like if converted to a cubemap and the individual sides are definetely not the same as the equirect image, they are modified in some way. When I get home I'll get a cubemap of the panorama I linked in the first post so you can see the differences.

        I know there has to be a practical way to do this in a program, i'd really rather not require my users download 2 different programs. Maybe ImageMagick has some answers, I'll take a look.

        Comment

        Working...