Ask Your Question
1

Convert Cubemap pixel coordinates to equivalents in Equirectangular

asked 2017-12-14 12:17:40 -0600

Finfa811 gravatar image

updated 2017-12-15 05:56:09 -0600

I have a set of coordinates of a 6-image Cubemap (Front, Back, Left, Right, Top, Bottom) as follows:

[ [160, 314], Front; [253, 231], Front; [345, 273], Left; [347, 92], Bottom; ... ]

Each image is 500x500p, being [0, 0] the top-left corner. I want to convert these coordinates to their equivalents in equirectangular, for a 2500x1250p image.

I don't need to convert the whole image, just the set of coordinates. Is there any straight-forward conversion for a specific pixel?

EDIT:

First of all, I want to insist on the fact that I don't have any image available, neither the 6 input images from the cubemap, nor the output equirectangular pano. What I have available is a set of pixel coordinates from 6 images that shape a skybox cubemap. I add a graphic example using 250x250p images:

Front image: image description

Right image: image description

And so on for the other 4 images (Back, Left, Top, Bottom).

I have set in red some points, these points will be my input. Those points would have their equivalents in an equirectangular panorama:

image description

I have used a 1000x500p pano in this case.

So the input is the pixel coordinates [x,y] of the red points in the cubemap, together with the image they belong to. The [0,0] pixel is the top-left corner of each image:

{ Lamp1: [194,175], front; Chair: [151,234], front; TV: [31,81], right; Door: [107,152], back; Lamp2: [125,190], left }

And the output I want to obtain is the pixel coordinates of the red points in the equirectangular panorama:

{ Lamp1: [831,304]; Chair: [784,362]; TV: [898,206]; Door: [228,283]; Lamp2: [500,326]  }

I would like to know how to map from one set of coordinates to the other:

CUBEMAP [194,175], front -> ? -> [831,304] EQUIRECTANGULAR
edit retag flag offensive close merge delete

Comments

can you explain those "coordinates" a bit more ? maybe even add the cubemap image to your question ?

berak gravatar imageberak ( 2017-12-14 12:29:09 -0600 )edit

@berak That's the point, I don't have the images. I explained it up above, I have a set of [x,y] pixel coordinates, coming from a set of 6 images (Front, Back, Left, Right, Top, Bottom), conforming a cubemap.

Each image is 500x500p and the origin [0,0] is at the top-left corner. I want to obtain the corresponding [x',y'] pixel in an equirectangular 2500x1250p panorama.

I don't want to convert the whole cubemap, just a specific pixel, knowing the image it belongs to.

Finfa811 gravatar imageFinfa811 ( 2017-12-14 12:40:29 -0600 )edit

ok, so we got a cross like skybox. look at the coords above, they don't make any sense. also, front appearing twice.

there's well known formulas using remap for this, but we need to verify your input first

berak gravatar imageberak ( 2017-12-14 12:56:55 -0600 )edit

@berak That's a script I am getting as input. It does make sense, e.g.: "[160, 314], Front" means the pixel x=160, y=314 from the front image, "[253, 231], Front" the pixel x=253, y=231 from the front image, "[345, 273], Left" the pixel x=347, y=92 from the left image and so on. I want to remap only the provided coordinates in the script to equirectangular.

Finfa811 gravatar imageFinfa811 ( 2017-12-14 13:10:21 -0600 )edit
2

Have you seen: http://paulbourke.net/miscellaneous/c... (especially "Converting to and from 6 cubic environment maps and a spherical map").

Maybe, if you can't figure it out, you could write to Paul Bourke and see if he has a clue for you.

You might also want to try asking your question on the gamedev.net forums. Environment maps are used in a lot of games, so someone might have some information for you.

sjhalayka gravatar imagesjhalayka ( 2017-12-14 18:30:43 -0600 )edit
1

@berak I don't get any coordinates, I obtain them from the output of another algorithm. Ok, I thought I was being pretty clear, but I'll edit the question with a graphic example when I find a free spot. Thank you for your help. @sjhalayka Thanks, I'll have a look to that.

Finfa811 gravatar imageFinfa811 ( 2017-12-15 02:04:06 -0600 )edit
1

@berak I've just edited the question. Hope it is clear now for you.

Finfa811 gravatar imageFinfa811 ( 2017-12-15 04:05:19 -0600 )edit
1

@Finfa811 , entirely, thanks a lot !

berak gravatar imageberak ( 2017-12-15 04:15:54 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-12-15 07:25:42 -0600

berak gravatar image

updated 2017-12-15 07:48:37 -0600

well, i think, you got your cubemaps in wrong order. using this convention:

image description

we can map cube coords to equirectangular in a straightforward way (some python code):

def get_theta_phi( _x, _y, _z):
    dv = math.sqrt(_x*_x + _y*_y + _z*_z)
    x = _x/dv
    y = _y/dv
    z = _z/dv
    theta = math.atan2(y, x)
    phi = math.asin(z)
    return theta, phi


# x,y position in cubemap
# cw  cube width
# W,H size of equirectangular image
def map_cube(x, y, side, cw, W, H):

    u = 2*(float(x)/cw - 0.5)
    v = 2*(float(y)/cw - 0.5)

    if side == "front":
        theta, phi = get_theta_phi( 1, u, v )
    elif side == "right":
        theta, phi = get_theta_phi( -u, 1, v )
    elif side == "left":
        theta, phi = get_theta_phi( u, -1, v )
    elif side == "back":
        theta, phi = get_theta_phi( -1, -u, v )
    elif side == "bottom":
        theta, phi = get_theta_phi( -v, u, 1 )
    elif side == "top":
        theta, phi = get_theta_phi( v, u, -1 )

    _u = 0.5+0.5*(theta/math.pi)
    _v = 0.5+(phi/math.pi)
    return _u*W,  _v*H


print map_cube(194, 175, "right", 250, 1000, 500)

(830.2741600023378, 303.610428544235)
edit flag offensive delete link more

Comments

So the steps are first normalizing to unit vectors, then converting to polar coordinates and finally converting back to the equivalents in equirectangular. Interesting... Yes, somehow I am getting the result of a different convention... No worries, I can fix that. The good news is that the solution works! Thanks.

Finfa811 gravatar imageFinfa811 ( 2017-12-15 12:01:51 -0600 )edit
1
berak gravatar imageberak ( 2017-12-15 12:21:06 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-12-14 12:17:40 -0600

Seen: 60 times

Last updated: Dec 15 '17