|
215 | 215 | " ),\n",
|
216 | 216 | " monai.transforms.ScaleIntensityd(keys=[\"img\"])\n",
|
217 | 217 | " ])\n",
|
218 |
| - " monai_transformed = transform({\"img\": monai_img})[\"img\"].transpose((1, 2, 0))\n", |
| 218 | + " monai_transformed = transform({\"img\": monai_img})[\"img\"].permute((1, 2, 0))\n", |
219 | 219 | "\n",
|
220 | 220 | " # sitk transform\n",
|
221 | 221 | " sitk_img = sitk.ReadImage(img_path)\n",
|
|
285 | 285 | "\n",
|
286 | 286 | "# Generate random samples inside the image, we will obtain the intensity/color values at these points.\n",
|
287 | 287 | "num_samples = 10\n",
|
288 |
| - "physical_points = np.array([np.random.randint(monai_img.shape[1:]) for _ in range(10)], dtype=np.float) # (10, 2)\n" |
| 288 | + "physical_points = np.array([np.random.randint(monai_img.shape[1:]) for _ in range(10)], dtype=float) # (10, 2)\n" |
289 | 289 | ]
|
290 | 290 | },
|
291 | 291 | {
|
|
322 | 322 | "# initialise ddf as a zero matrix\n",
|
323 | 323 | "ddf = torch.zeros(2, height, width).to(torch.float) # (2, H, W)\n",
|
324 | 324 | "# add displacement of y coordinate to sampled locations\n",
|
325 |
| - "for i, pnt in enumerate(physical_points.astype(np.long)):\n", |
| 325 | + "for i, pnt in enumerate(physical_points.astype(int)):\n", |
326 | 326 | " ddf[0, pnt[0], pnt[1]] += i\n",
|
327 | 327 | "\n",
|
328 | 328 | "# initialise warp layer\n",
|
|
360 | 360 | "sitk_displacement_img = sitk.Image([width, height], sitk.sitkVectorFloat64, sitk_img.GetDimension())\n",
|
361 | 361 | "# add displacement of y coordinate to sampled locations\n",
|
362 | 362 | "for i, pnt in enumerate(physical_points):\n",
|
363 |
| - " sitk_displacement_img[int(pnt[1]), int(pnt[0])] = np.array([0, i], dtype=np.float)\n", |
| 363 | + " sitk_displacement_img[int(pnt[1]), int(pnt[0])] = np.array([0, i], dtype=float)\n", |
364 | 364 | "\n",
|
365 | 365 | "# select linear interpolater to match `bilinear` mode in MONAI\n",
|
366 | 366 | "interpolator_enum = sitk.sitkLinear\n",
|
|
420 | 420 | }
|
421 | 421 | ],
|
422 | 422 | "source": [
|
423 |
| - "for _, pnt in enumerate(physical_points.astype(np.long)):\n", |
| 423 | + "for _, pnt in enumerate(physical_points.astype(int)):\n", |
424 | 424 | " print(f\"at location {pnt}: original intensity {monai_img[:, pnt[0], pnt[1]]} \" +\n",
|
425 | 425 | " f\"resampled to {monai_resample[:, pnt[0], pnt[1]]} by MONAI and {sitk_resample[pnt[0], pnt[1]]} by SITK\")"
|
426 | 426 | ]
|
|
449 | 449 | "source": [
|
450 | 450 | "img = monai.transforms.LoadImaged(keys=\"img\")({\"img\": f\"{root_dir}/mri.nii\"})[\"img\"]\n",
|
451 | 451 | "# W, H, D -> D, H, W\n",
|
452 |
| - "img = img.transpose((2, 1, 0))" |
| 452 | + "img = img.permute((2, 1, 0))" |
453 | 453 | ]
|
454 | 454 | },
|
455 | 455 | {
|
|
689 | 689 | "name": "python",
|
690 | 690 | "nbconvert_exporter": "python",
|
691 | 691 | "pygments_lexer": "ipython3",
|
692 |
| - "version": "3.8.12" |
| 692 | + "version": "3.8.0" |
693 | 693 | },
|
694 | 694 | "widgets": {
|
695 | 695 | "application/vnd.jupyter.widget-state+json": {
|
|
0 commit comments