Skip to content

Commit

Permalink
Make pinhole pose compatible with renderer (#361)
Browse files Browse the repository at this point in the history
* Fix multiplier

* Add tutorial for DiffDRR to pinhole conversion

* Fix inverse projection
  • Loading branch information
eigenvivek authored Jan 11, 2025
1 parent 11b1f0a commit febb648
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 15 deletions.
4 changes: 2 additions & 2 deletions diffdrr/drr.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ def inverse_projection(
pts: torch.Tensor,
):
"""Backproject points in pixel plane (2D) onto the image plane in world coordinates (3D)."""
# pts = pts.flip(-1)
pts[..., 1] = self.detector.height - pts[..., 1]
if self.detector.reverse_x_axis:
pts[..., 1] = self.detector.width - pts[..., 1]
pts[..., 0] = self.detector.width - pts[..., 0]
x = self.detector.sdd * torch.einsum(
"ij, bnj -> bni",
self.detector.intrinsic.inverse(),
Expand Down
2 changes: 1 addition & 1 deletion diffdrr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_pinhole_camera(
pose = deepcopy(pose).to(device="cpu", dtype=dtype)

# Make the intrinsic matrix (in pixels)
multiplier = -1 if drr.subject.orientation == "PA" else 1
multiplier = -1 if drr.subject.orientation == "AP" else 1
fx = multiplier * drr.detector.sdd / drr.detector.delx
fy = multiplier * drr.detector.sdd / drr.detector.dely
u0 = drr.detector.x0 / drr.detector.delx + drr.detector.width / 2
Expand Down
4 changes: 2 additions & 2 deletions notebooks/api/00_drr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@
" pts: torch.Tensor,\n",
"):\n",
" \"\"\"Backproject points in pixel plane (2D) onto the image plane in world coordinates (3D).\"\"\"\n",
" # pts = pts.flip(-1)\n",
" pts[..., 1] = self.detector.height - pts[..., 1]\n",
" if self.detector.reverse_x_axis:\n",
" pts[..., 1] = self.detector.width - pts[..., 1]\n",
" pts[..., 0] = self.detector.width - pts[..., 0]\n",
" x = self.detector.sdd * torch.einsum(\n",
" \"ij, bnj -> bni\",\n",
" self.detector.intrinsic.inverse(),\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/api/07_utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
" pose = deepcopy(pose).to(device=\"cpu\", dtype=dtype)\n",
"\n",
" # Make the intrinsic matrix (in pixels)\n",
" multiplier = -1 if drr.subject.orientation == \"PA\" else 1\n",
" multiplier = -1 if drr.subject.orientation == \"AP\" else 1\n",
" fx = multiplier * drr.detector.sdd / drr.detector.delx\n",
" fy = multiplier * drr.detector.sdd / drr.detector.dely\n",
" u0 = drr.detector.x0 / drr.detector.delx + drr.detector.width / 2\n",
Expand Down
128 changes: 119 additions & 9 deletions notebooks/tutorials/introduction.ipynb

Large diffs are not rendered by default.

0 comments on commit febb648

Please sign in to comment.