<p>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)</p>

<p>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:</p>

<p><span class="math-container">$u = 4095 / 4096 = 0.99976$</span>
<span class="math-container">$v = 2047 / 2048 = 0.99951$</span></p>

<p>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:</p>

<p><span class="math-container">$u = 2047 / 4096 = 0.49975$</span>
<span class="math-container">$v = 1023 / 2048 = 0.49951$</span></p>

CC BY-SA 4.0
2019-11-12T15:55:46.733Z
2019-11-12T15:55:46.733Z
Tare
<p>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. </p>

<pre><code>phi = 2*Pi*u
cos(theta) = 2*v -1
</code></pre>

<p>But how do i get <code>u</code> and <code>v</code> ? In the article he talks about this: </p>

<blockquote>
  <p>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</p>
</blockquote>

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

<p>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!</p>

<texture><mapping>
convert image pixel dimensions to UV
FutureCake
# convert image pixel dimensions to UV

(Asked by: username_0 on 2019-11-12)

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!

**Tags:** texture, mapping


---

## 1 answers

### Answer by username_1 on 2019-11-12. Score: 1 | Accepted 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$


---

