Skip to content

Commit febb648

Browse files
authored
Make pinhole pose compatible with renderer (#361)
* Fix multiplier * Add tutorial for DiffDRR to pinhole conversion * Fix inverse projection
1 parent 11b1f0a commit febb648

5 files changed

Lines changed: 125 additions & 15 deletions

File tree

diffdrr/drr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ def inverse_projection(
283283
pts: torch.Tensor,
284284
):
285285
"""Backproject points in pixel plane (2D) onto the image plane in world coordinates (3D)."""
286-
# pts = pts.flip(-1)
286+
pts[..., 1] = self.detector.height - pts[..., 1]
287287
if self.detector.reverse_x_axis:
288-
pts[..., 1] = self.detector.width - pts[..., 1]
288+
pts[..., 0] = self.detector.width - pts[..., 0]
289289
x = self.detector.sdd * torch.einsum(
290290
"ij, bnj -> bni",
291291
self.detector.intrinsic.inverse(),

diffdrr/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_pinhole_camera(
110110
pose = deepcopy(pose).to(device="cpu", dtype=dtype)
111111

112112
# Make the intrinsic matrix (in pixels)
113-
multiplier = -1 if drr.subject.orientation == "PA" else 1
113+
multiplier = -1 if drr.subject.orientation == "AP" else 1
114114
fx = multiplier * drr.detector.sdd / drr.detector.delx
115115
fy = multiplier * drr.detector.sdd / drr.detector.dely
116116
u0 = drr.detector.x0 / drr.detector.delx + drr.detector.width / 2

notebooks/api/00_drr.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@
434434
" pts: torch.Tensor,\n",
435435
"):\n",
436436
" \"\"\"Backproject points in pixel plane (2D) onto the image plane in world coordinates (3D).\"\"\"\n",
437-
" # pts = pts.flip(-1)\n",
437+
" pts[..., 1] = self.detector.height - pts[..., 1]\n",
438438
" if self.detector.reverse_x_axis:\n",
439-
" pts[..., 1] = self.detector.width - pts[..., 1]\n",
439+
" pts[..., 0] = self.detector.width - pts[..., 0]\n",
440440
" x = self.detector.sdd * torch.einsum(\n",
441441
" \"ij, bnj -> bni\",\n",
442442
" self.detector.intrinsic.inverse(),\n",

notebooks/api/07_utils.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
" pose = deepcopy(pose).to(device=\"cpu\", dtype=dtype)\n",
185185
"\n",
186186
" # Make the intrinsic matrix (in pixels)\n",
187-
" multiplier = -1 if drr.subject.orientation == \"PA\" else 1\n",
187+
" multiplier = -1 if drr.subject.orientation == \"AP\" else 1\n",
188188
" fx = multiplier * drr.detector.sdd / drr.detector.delx\n",
189189
" fy = multiplier * drr.detector.sdd / drr.detector.dely\n",
190190
" u0 = drr.detector.x0 / drr.detector.delx + drr.detector.width / 2\n",

notebooks/tutorials/introduction.ipynb

Lines changed: 119 additions & 9 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)