<p>Typically the normal vector, which has XYZ components in [−1, 1] is linearly mapped to the RGB range [0, 255]. You can retrieve the normal vector by reversing this mapping.</p>
<p>For completeness, the encoding is:<br />
<span class="math-container">$$
r = \text{round}((0.5x + 0.5) \cdot 255) \\
g = \text{round}((0.5y + 0.5) \cdot 255) \\
b = \text{round}((0.5z + 0.5) \cdot 255)
$$</span></p>
<p>Decoding is:
<span class="math-container">$$
x = (r/255) \cdot 2 - 1 \\
y = (g/255) \cdot 2 - 1 \\
z = (b/255) \cdot 2 - 1
$$</span></p>

CC BY-SA 4.0
2020-11-11T21:11:07.030Z
Thank you. Is there a convention as to which channel corresponds to which axis? e.g., R=X, G=Y, B=Z etc
user1696420
CC BY-SA 4.0
2020-11-11T21:29:55.070Z
Yes always R=X, G=Y, B=Z. There are different conventions about which ways the axes point, though, such as Y up versus Z up.
Nathan Reed
CC BY-SA 4.0
2020-11-11T05:11:26.547Z
2020-11-11T05:11:26.547Z
Nathan Reed
<p>Using deep learning to estimate surface normals from monocular RGB images is a common task. The resulting image generally looks like this:</p>
<p><img src="https://i.sstatic.net/StN14.jpg" alt="RBG to surface normal map" /></p>
<p>My question is how can I use this map to actually draw a normal vector (arrow) for any given point on the image? For example, I want to draw a line on the countertop that points up.</p>
<p>Most relevant tidbit I found on the topic: &quot;The RGB color channels (red, green, and blue) in a normal map correspond to the respective X, Y, and Z coordinates of surface normals.&quot;</p>
<p>But I don't get what this means. The values are standard RGB, i.e., for each coordinate, you get three numbers in range [0, 255]. Just by how color changes between surfaces, it is clearly related to normals (obviously) but when I tried quiver plots using matlab I couldn't get reasonable results.</p>
<p>TLDR: What is the relation between surface normal maps and actual normal vectors? How can I draw a 3d line given a point on the image which represents the normal vector perpendicular to that surface at that point?</p>

<normal-mapping>
How to draw surface normals from surface normal maps?
user1696420
# How to draw surface normals from surface normal maps?

(Asked by: username_0 on 2020-11-11)

Using deep learning to estimate surface normals from monocular RGB images is a common task. The resulting image generally looks like this:

![RBG to surface normal map](https://i.sstatic.net/StN14.jpg)

My question is how can I use this map to actually draw a normal vector (arrow) for any given point on the image? For example, I want to draw a line on the countertop that points up.

Most relevant tidbit I found on the topic: "The RGB color channels (red, green, and blue) in a normal map correspond to the respective X, Y, and Z coordinates of surface normals."

But I don't get what this means. The values are standard RGB, i.e., for each coordinate, you get three numbers in range [0, 255]. Just by how color changes between surfaces, it is clearly related to normals (obviously) but when I tried quiver plots using matlab I couldn't get reasonable results.

TLDR: What is the relation between surface normal maps and actual normal vectors? How can I draw a 3d line given a point on the image which represents the normal vector perpendicular to that surface at that point?

**Tags:** normal-mapping


---

## 1 answers

### Answer by username_1 on 2020-11-11. Score: 4 | Accepted answer

Typically the normal vector, which has XYZ components in [−1, 1] is linearly mapped to the RGB range [0, 255]. You can retrieve the normal vector by reversing this mapping.

For completeness, the encoding is:  
$$
r = \text{round}((0.5x + 0.5) \cdot 255) \\
g = \text{round}((0.5y + 0.5) \cdot 255) \\
b = \text{round}((0.5z + 0.5) \cdot 255)
$$

Decoding is:
$$
x = (r/255) \cdot 2 - 1 \\
y = (g/255) \cdot 2 - 1 \\
z = (b/255) \cdot 2 - 1
$$

> **Comments:**
> **username_0**: Thank you. Is there a convention as to which channel corresponds to which axis? e.g., R=X, G=Y, B=Z etc  
> **username_1**: Yes always R=X, G=Y, B=Z. There are different conventions about which ways the axes point, though, such as Y up versus Z up.  

---

