Skip to content

Commit

Permalink
Switch DeepFluoro orientation to PA
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenvivek committed Aug 12, 2024
1 parent 967ecac commit 1d8ac7d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 28 deletions.
15 changes: 10 additions & 5 deletions diffdrrdata/deepfluoro.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import h5py
import numpy as np
import torch
from diffdrr.data import read
from diffdrr.pose import RigidTransform
from diffdrr.utils import parse_intrinsic_matrix
from torchio import LabelMap, ScalarImage, Subject
from torchio.transforms.preprocessing import ToCanonical
from torchvision.transforms.functional import center_crop, gaussian_blur

from diffdrr.data import read
from diffdrr.pose import RigidTransform
from diffdrr.utils import parse_intrinsic_matrix

from .utils import load_file

# %% ../notebooks/00_deepfluoro.ipynb 6
Expand Down Expand Up @@ -97,6 +98,7 @@ def __getitem__(self, idx):
.compose(self.world2camera.inverse())
.compose(pose)
.compose(self.anatomical2world)
.compose(self.rot_180)
)
if self.rot_180_for_up(idx):
img = torch.rot90(img, k=2)
Expand All @@ -118,11 +120,11 @@ def parse_volume(subject, bone_attenuation_multiplier, labels):
# Get all parts of the volume
volume = subject["vol/pixels"][:]
volume = np.swapaxes(volume, 0, 2).copy()
volume = torch.from_numpy(volume).unsqueeze(0)
volume = torch.from_numpy(volume).unsqueeze(0).flip(1).flip(2)

mask = subject["vol-seg/image/pixels"][:]
mask = np.swapaxes(mask, 0, 2).copy()
mask = torch.from_numpy(mask).unsqueeze(0)
mask = torch.from_numpy(mask).unsqueeze(0).flip(1).flip(2)

affine = np.eye(4)
affine[:3, :3] = subject["vol/dir-mat"][:]
Expand Down Expand Up @@ -161,10 +163,13 @@ def parse_volume(subject, bone_attenuation_multiplier, labels):
volume=volume,
labelmap=labelmap,
labels=labels,
orientation="PA",
bone_attenuation_multiplier=bone_attenuation_multiplier,
label_def=defns,
fiducials=fiducials,
)
reorient = RigidTransform(torch.diag(torch.tensor([-1.0, -1.0, 1.0, 1.0])))
subject.fiducials = reorient(subject.fiducials)

return subject, anatomical2world

Expand Down
90 changes: 68 additions & 22 deletions notebooks/00_deepfluoro.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/deepfluoro_camera_poses.html

Large diffs are not rendered by default.

0 comments on commit 1d8ac7d

Please sign in to comment.