# convert image pixel dimensions to UV

Hi i am rather new to computergraphics but i am trying to map an equirectangular image (360 video) to the inside of a sphere now i found the following formula to do this.

phi = 2*Pi*u
cos(theta) = 2*v -1


But how do i get u and v ? In the article he talks about this:

So we can just project the sphere points in the xy plane onto the unit radius cylinder and unwrap it! If we have such an image with texture coordinates (u,v) in [0,1]^2

But how do i get those texture coordinates from and image with lets say the following dimensions 4096x2048 pixels?

Sorry if this is a bit vague, i am trying to understand it myself. If clarification is needed i am happy to edit my question!

## 1 Answer

UV coordinates are defined such that (0, 0) is your lower left (or upper left, depending on what you're working with) corner of the image and (1, 1) the opposite corner (technically (1, 1) is outside the UV range, but we ignore this for easiness sake). Thus, if you want the exact middle, you obviously get (0.5, 0.5)

Now with your image, the first pixel lower left is the pixel at (0, 0) as well. The pixel in the opposite corner is (4095, 2047). To get to the (1, 1) corner, you need to take that corner pixel and divide it's coordinates by the image's width and height respectively. here you will see, that the (1, 1) does not fit exactly:

$$u = 4095 / 4096 = 0.99976$$ $$v = 2047 / 2048 = 0.99951$$

The same principle applies to any other pixel of your image, you just have to divide by the image's width in pixels. Your center pixel is at (2047, 1023) (or the image borders on this pixel and three of its neighbours). The resulting UVs are:

$$u = 2047 / 4096 = 0.49975$$ $$v = 1023 / 2048 = 0.49951$$