import matplotlib.pyplot as plt
import numpy as np
import torch
from diffdrr.drr import DRR
Spherical coordinates
Explanation of Euler angles for parameterizing the C-arm
DiffDRR camera matrix conventions
Code
= 1.0
sdr = 0, 0, 0
alpha, gamma, beta = 10, -10, -40
bx, by, bz = torch.Tensor([[alpha, beta, gamma]])
rotations = torch.tensor([[bx, by, bz]])
translations
= DRR(
drr =np.zeros([512, 512, 133]),
volume=[1, 1, 1],
spacing=sdr,
sdr=5,
height=0.75,
delx"cpu") ).to(
= plt.figure()
fig for i in range(8):
= (i / 8) * torch.pi
alpha = (0 / 8) * torch.pi
beta = (0 / 8) * torch.pi
gamma = torch.Tensor([[alpha, beta, gamma]])
rotations
= drr.detector(rotations, translations, "euler_angles", "ZYX")
source, rays = source.detach().cpu()
source_ = rays.permute(2, 0, 1).detach().cpu()
rays_
= fig.add_subplot(2, 4, i+1, projection='3d')
ax set(title=f"$\\alpha=\\frac{{{i}}}{{8}}\pi$")
ax.0, 0, 0] , source_[0, 0, 1] , source_[0, 0, 2] , c="black")
ax.scatter(source_[0].flatten(), rays_[1].flatten(), rays_[2].flatten(), c=torch.arange(25), cmap="jet")
ax.scatter(rays_[
= rays_.reshape(3, -1)
xs, ys, zs for x, y, z in zip(xs, ys, zs):
0, 0, 0], x], [source_[0, 0, 1], y], [source_[0, 0, 2], z], "k", alpha=0.2)
ax.plot([source_[
set(xlabel="x", ylabel="y", zlabel="z")
ax.set(xlim=[8,12], ylim=[-12,-8], zlim=[-42,-38])
ax.
plt.tight_layout() plt.show()
= plt.figure()
fig for i in range(8):
= (0 / 8) * torch.pi
alpha = (i / 8) * torch.pi
beta = (0 / 8) * torch.pi
gamma = torch.Tensor([[alpha, beta, gamma]])
rotations
= drr.detector(rotations, translations, "euler_angles", "ZYX")
source, rays = source.detach().cpu()
source_ = rays.permute(2, 0, 1).detach().cpu()
rays_
= fig.add_subplot(2, 4, i+1, projection='3d')
ax set(title=f"$\\beta=\\frac{{{i}}}{{8}}\pi$")
ax.0, 0, 0] , source_[0, 0, 1] , source_[0, 0, 2] , c="black")
ax.scatter(source_[0].flatten(), rays_[1].flatten(), rays_[2].flatten(), c=torch.arange(25), cmap="jet")
ax.scatter(rays_[
= rays_.reshape(3, -1)
xs, ys, zs for x, y, z in zip(xs, ys, zs):
0, 0, 0], x], [source_[0, 0, 1], y], [source_[0, 0, 2], z], "k", alpha=0.2)
ax.plot([source_[
set(xlabel="x", ylabel="y", zlabel="z")
ax.set(xlim=[8,12], ylim=[-12,-8], zlim=[-42,-38])
ax.
plt.tight_layout() plt.show()
= plt.figure()
fig for i in range(8):
= (0 / 8) * torch.pi
alpha = (0 / 8) * torch.pi
beta = (i / 8) * torch.pi
gamma = torch.Tensor([[alpha, beta, gamma]])
rotations
= drr.detector(rotations, translations, "euler_angles", "ZYX")
source, rays = source.detach().cpu()
source_ = rays.permute(2, 0, 1).detach().cpu()
rays_
= fig.add_subplot(2, 4, i+1, projection='3d')
ax set(title=f"$\\gamma=\\frac{{{i}}}{{8}}\pi$")
ax.0, 0, 0] , source_[0, 0, 1] , source_[0, 0, 2] , label="Source", c="black")
ax.scatter(source_[0].flatten(), rays_[1].flatten(), rays_[2].flatten(), label="Targets", c=torch.arange(25), cmap="jet")
ax.scatter(rays_[
= rays_.reshape(3, -1)
xs, ys, zs for x, y, z in zip(xs, ys, zs):
0, 0, 0], x], [source_[0, 0, 1], y], [source_[0, 0, 2], z], "k", alpha=0.2)
ax.plot([source_[
set(xlabel="x", ylabel="y", zlabel="z")
ax.set(xlim=[8,12], ylim=[-12,-8], zlim=[-42,-38])
ax.
plt.tight_layout() plt.show()