|
151 | 151 | "#| export\n",
|
152 | 152 | "def _get_alphas(source, target, spacing, dims, eps):\n",
|
153 | 153 | " # Get the CT sizing and spacing parameters\n",
|
154 |
| - " dx, dy, dz = spacing\n", |
155 |
| - " nx, ny, nz = dims\n", |
| 154 | + " alphax = torch.arange(dims[0]).to(source) * spacing[0]\n", |
| 155 | + " alphay = torch.arange(dims[1]).to(source) * spacing[1]\n", |
| 156 | + " alphaz = torch.arange(dims[2]).to(source) * spacing[2]\n", |
156 | 157 | "\n",
|
157 | 158 | " # Get the alpha at each plane intersection\n",
|
158 | 159 | " sx, sy, sz = source[..., 0], source[..., 1], source[..., 2]\n",
|
159 |
| - " alphax = torch.arange(nx).to(source) * dx\n", |
160 |
| - " alphay = torch.arange(ny).to(source) * dy\n", |
161 |
| - " alphaz = torch.arange(nz).to(source) * dz\n", |
162 | 160 | " alphax = alphax.expand(len(source), 1, -1) - sx.unsqueeze(-1)\n",
|
163 | 161 | " alphay = alphay.expand(len(source), 1, -1) - sy.unsqueeze(-1)\n",
|
164 | 162 | " alphaz = alphaz.expand(len(source), 1, -1) - sz.unsqueeze(-1)\n",
|
|
175 | 173 | " alphas[~good_idxs] = torch.nan\n",
|
176 | 174 | "\n",
|
177 | 175 | " # Sort the alphas by ray, putting nans at the end of the list\n",
|
178 |
| - " # Drop indices where alphas for all rays are nan\n", |
179 | 176 | " alphas = torch.sort(alphas, dim=-1).values\n",
|
| 177 | + " \n", |
| 178 | + " # Drop indices where alphas for all rays are nan\n", |
180 | 179 | " alphas = alphas[..., ~alphas.isnan().all(dim=0).all(dim=0)]\n",
|
| 180 | + "\n", |
181 | 181 | " return alphas\n",
|
182 | 182 | "\n",
|
183 | 183 | "\n",
|
|
219 | 219 | " return idxs"
|
220 | 220 | ]
|
221 | 221 | },
|
| 222 | + { |
| 223 | + "cell_type": "markdown", |
| 224 | + "metadata": {}, |
| 225 | + "source": [ |
| 226 | + "## Compilier-friendly Siddon" |
| 227 | + ] |
| 228 | + }, |
| 229 | + { |
| 230 | + "cell_type": "code", |
| 231 | + "execution_count": null, |
| 232 | + "metadata": {}, |
| 233 | + "outputs": [], |
| 234 | + "source": [] |
| 235 | + }, |
222 | 236 | {
|
223 | 237 | "cell_type": "markdown",
|
224 | 238 | "metadata": {},
|
|
238 | 252 | "cell_type": "code",
|
239 | 253 | "execution_count": null,
|
240 | 254 | "metadata": {},
|
241 |
| - "outputs": [ |
242 |
| - { |
243 |
| - "ename": "NameError", |
244 |
| - "evalue": "name 'torch' is not defined", |
245 |
| - "output_type": "error", |
246 |
| - "traceback": [ |
247 |
| - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
248 |
| - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
249 |
| - "Cell \u001b[0;32mIn[1], line 5\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#| export\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtorch\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mnn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfunctional\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m grid_sample\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mTrilinear\u001b[39;00m(\u001b[43mtorch\u001b[49m\u001b[38;5;241m.\u001b[39mnn\u001b[38;5;241m.\u001b[39mModule):\n\u001b[1;32m 6\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;124;03m Instead of computing the exact line integral over the voxel grid (i.e., Siddon's method), we can sample colors at points along the each ray using trilinear interpolation.\u001b[39;00m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;124;03m \u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124;03m where $\\mathbf V[\\cdot]$ is the trilinear interpolation function and $M$ is the number of points sampled per ray.\u001b[39;00m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 17\u001b[0m near\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.0\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 20\u001b[0m eps\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1e-8\u001b[39m,\n\u001b[1;32m 21\u001b[0m ):\n", |
250 |
| - "\u001b[0;31mNameError\u001b[0m: name 'torch' is not defined" |
251 |
| - ] |
252 |
| - } |
253 |
| - ], |
| 255 | + "outputs": [], |
254 | 256 | "source": [
|
255 | 257 | "#| export\n",
|
256 | 258 | "from torch.nn.functional import grid_sample\n",
|
|
0 commit comments