|
108 | 108 | "outputs": [],
|
109 | 109 | "source": [
|
110 | 110 | "#| export\n",
|
| 111 | + "from diffdrr.pose import RigidTransform\n", |
| 112 | + "\n", |
| 113 | + "\n", |
111 | 114 | "def read(\n",
|
112 | 115 | " volume: str | Path | ScalarImage, # CT volume\n",
|
113 | 116 | " labelmap: str | Path | LabelMap = None, # Labelmap for the CT volume\n",
|
114 | 117 | " labels: int | list = None, # Labels from the mask of structures to render\n",
|
115 | 118 | " orientation: str | None = \"AP\", # Frame-of-reference change\n",
|
116 | 119 | " bone_attenuation_multiplier: float = 1.0, # Scalar multiplier on density of high attenuation voxels\n",
|
117 | 120 | " fiducials: torch.Tensor = None, # 3D fiducials in world coordinates\n",
|
| 121 | + " transform: RigidTransform = None, # RigidTransform to apply to the volume's affine\n", |
| 122 | + " center_volume: bool = True, # Move the volume's isocenter to the world origin\n", |
118 | 123 | " **kwargs, # Any additional information to be stored in the torchio.Subject\n",
|
119 | 124 | ") -> Subject:\n",
|
120 | 125 | " \"\"\"\n",
|
|
128 | 133 | " else:\n",
|
129 | 134 | " volume = ScalarImage(volume)\n",
|
130 | 135 | "\n",
|
131 |
| - " # Convert the volume to density\n", |
132 |
| - " density = transform_hu_to_density(volume.data, bone_attenuation_multiplier)\n", |
133 |
| - " density = ScalarImage(tensor=density, affine=volume.affine)\n", |
134 |
| - "\n", |
135 | 136 | " # Read the mask if passed\n",
|
136 | 137 | " if labelmap is not None:\n",
|
137 | 138 | " if isinstance(labelmap, LabelMap):\n",
|
|
142 | 143 | " else:\n",
|
143 | 144 | " mask = None\n",
|
144 | 145 | "\n",
|
| 146 | + " # Optionally apply transform\n", |
| 147 | + " if transform is not None:\n", |
| 148 | + " T = transform.matrix[0].numpy()\n", |
| 149 | + " volume = ScalarImage(tensor=volume.data, affine=T.dot(volume.affine))\n", |
| 150 | + " \n", |
| 151 | + " # Convert the volume to density\n", |
| 152 | + " density = transform_hu_to_density(volume.data, bone_attenuation_multiplier)\n", |
| 153 | + " density = ScalarImage(tensor=density, affine=volume.affine)\n", |
| 154 | + "\n", |
145 | 155 | " # Frame-of-reference change\n",
|
146 | 156 | " if orientation == \"AP\":\n",
|
147 | 157 | " # Rotates the C-arm about the x-axis by 90 degrees\n",
|
|
188 | 198 | " **kwargs,\n",
|
189 | 199 | " )\n",
|
190 | 200 | "\n",
|
191 |
| - " # Canonicalize the images by converting to RAS+ and moving the\n", |
192 |
| - " # Subject's isocenter to the origin in world coordinates\n", |
193 |
| - " subject = canonicalize(subject)\n", |
| 201 | + " # Move the subject's isocenter to the origin in world coordinates\n", |
| 202 | + " if center_volume:\n", |
| 203 | + " subject = canonicalize(subject)\n", |
194 | 204 | "\n",
|
195 | 205 | " # Apply mask\n",
|
196 | 206 | " if labels is not None:\n",
|
|
0 commit comments