import matplotlib.pyplot as plt
import numpy as np
import torch
from diffdrr.drr import DRR
Spherical Coordinates
Code
= 1.0
sdr = 0, 0, 0
theta, gamma, phi = 10, -10, -40
bx, by, bz = torch.Tensor([[sdr, theta, phi, gamma, bx, by, bz]])
params
= DRR(
drr =np.zeros([512, 512, 133]),
volume=[1, 1, 1],
spacing=5,
height=0.75,
delx=params,
params"cuda" if torch.cuda.is_available() else "cpu") ).to(
= plt.figure()
fig for i in range(8):
= (i / 8) * torch.pi
theta = (0 / 8) * torch.pi
phi = (0 / 8) * torch.pi
gamma = torch.Tensor([[sdr, theta, phi, gamma, bx, by, bz]])
params
drr._update_params(params)= drr.detector.make_xrays(drr.sdr, drr.rotations, drr.translations)
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"$\\theta=\\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
theta = (i / 8) * torch.pi
phi = (0 / 8) * torch.pi
gamma = torch.Tensor([[sdr, theta, phi, gamma, bx, by, bz]])
params
drr._update_params(params)= drr.detector.make_xrays(drr.sdr, drr.rotations, drr.translations)
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"$\\phi=\\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
theta = (0 / 8) * torch.pi
phi = (i / 8) * torch.pi
gamma = torch.Tensor([[sdr, theta, phi, gamma, bx, by, bz]])
params
drr._update_params(params)= drr.detector.make_xrays(drr.sdr, drr.rotations, drr.translations)
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()