I try to understand how blender processes normal maps. As an exercise I try to create a bump map of a half sphere, where each pixel's rgb values describe the normal of the surface of the sphere. That a point $(x,y,z)$ lies on the unit sphere means $x^2 + y^2+z^2 = 1$. Also the normal vector is equal to the point itself, because the vector sticks out of the sphere perpendicularly. Then, by solving for $z$, I can map each $(x,y)$ onto its corresponding normal vector via $$n(x,y) = (x,y,\sqrt{1-x^2-y^2}).$$ From the code below I get this image: which in blender produces this result: Code
import numpy as np
import matplotlib.pyplot as plt
n= 640
x = np.linspace(-1,1,n)
y = np.linspace(-1,1,n)
X,Y = np.meshgrid(x,y)
Z = (1 - X*X - Y*Y)**0.5
mask = X**2 + Y**2 <= 1
Z[~mask] = 0
N = np.dstack((X,Y,Z))*mask[:,:,np.newaxis]
N = (N + 1 ) / 2
plt.imshow(N)
cv2.imwrite("sphere_normals.png", N)