I'm trying to recreate an X-ray projection
I have 3D coordinates of an object of shape (100,3), spherical coordinates of the camera (theta, phi, distance), distance from camera to image, and size of image (512x512)
There are plenty of tutorials out there but I am struggling to get plausible results
Here is what I have done so far
def spherical_2_cartesian (phi, theta, p):
x = p * np.sin(phi) * np.cos(theta)
y = p * np.sin(phi) * np.sin(theta)
z = p * np.cos(phi)
return x,y,z
xa,ya,za = spherical_2_cartesian (23.1, 32.6, 730.0779523)
L = [xa,ya,za]
L = L / np.linalg.norm(L)
s = np.cross(L, [0,1,0])
s = s / np.linalg.norm(s)
u_prime = s * L
R = np.array([s, u_prime, -L])
t = np.dot(-R,[xa,ya,za])
extrinsic = np.column_stack((R, t))
f = 1066 ## distance from source to image plane
cx, cy = 512.0/2, 512.0/2 ## image size / 2
intrisic = np.array([[f, 0, cx], [0, f, cy], [0, 0, 1]])
mesh_homo = np.concatenate((mesh_coords,np.ones((len(mesh_coords),1))), axis=1)
mesh_in_camera_coords = np.dot(extrinsic,np.swapaxes(mesh_homo, 0, 1))
homogenous = np.dot(intrisic, mesh_in_camera_coords)
x = homogenous[0] / homogenous[2]
y = homogenous[1] / homogenous[2]
Can anyone see where I'm going wrong?
SOLVED: For those interested, the correct way to build an extrinsic matrix for angiographic x-ray is described in this paper: