Skip to content

Commit bdaf35c

Browse files
authored
Merge pull request #212 from jhlegarreta/enh/plot-gt-motion-pet-notebook
ENH: Plot ground truth motion in PET notebook
2 parents ec23995 + 2cdb97e commit bdaf35c

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

docs/notebooks/pet_motion_estimation.ipynb

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,19 +2480,19 @@
24802480
" motion_parameters.append([tx, ty, tz, rx, ry, rz])\n",
24812481
"\n",
24822482
"motion_parameters = np.array(motion_parameters)\n",
2483-
"fd = compute_fd(motion_parameters)\n",
2483+
"estimated_fd = compute_fd(motion_parameters)\n",
24842484
"\n",
24852485
"# Creating a DataFrame for better visualization\n",
24862486
"df_motion = pd.DataFrame(\n",
24872487
" {\n",
2488-
" \"Frame\": np.arange(len(fd)),\n",
2488+
" \"Frame\": np.arange(len(estimated_fd)),\n",
24892489
" \"Translation X\": motion_parameters[:, 0],\n",
24902490
" \"Translation Y\": motion_parameters[:, 1],\n",
24912491
" \"Translation Z\": motion_parameters[:, 2],\n",
24922492
" \"Rotation X\": motion_parameters[:, 3],\n",
24932493
" \"Rotation Y\": motion_parameters[:, 4],\n",
24942494
" \"Rotation Z\": motion_parameters[:, 5],\n",
2495-
" \"Framewise Displacement (mm)\": fd,\n",
2495+
" \"Framewise Displacement (mm)\": estimated_fd,\n",
24962496
" }\n",
24972497
")"
24982498
]
@@ -2549,6 +2549,51 @@
25492549
"plt.show()"
25502550
]
25512551
},
2552+
{
2553+
"metadata": {},
2554+
"cell_type": "markdown",
2555+
"source": "For the dataset used in this example, we have access to the ground truth motion parameters that were used to corrupt the motion-free dataset. Let's now plot the ground truth motion to enable a visual comparison with the estimated motion.",
2556+
"id": "e3f45164598d16f0"
2557+
},
2558+
{
2559+
"metadata": {},
2560+
"cell_type": "code",
2561+
"outputs": [],
2562+
"execution_count": null,
2563+
"source": [
2564+
"from nifreeze.viz.motion_viz import plot_volumewise_motion\n",
2565+
"\n",
2566+
"%matplotlib inline\n",
2567+
"\n",
2568+
"motion_gt_fname = (\n",
2569+
" DATA_PATH\n",
2570+
" / \"pet_data\"\n",
2571+
" / \"sub-02\"\n",
2572+
" / \"ses-baseline\"\n",
2573+
" / \"pet\"\n",
2574+
" / \"sub-02_ses-baseline_ground_truth_motion.csv\"\n",
2575+
")\n",
2576+
"motion_gt_df = pd.read_csv(motion_gt_fname)\n",
2577+
"\n",
2578+
"frames = motion_gt_df[\"frame\"].to_numpy()\n",
2579+
"\n",
2580+
"# Construct motion_params array with shape (n_frames, 6): [trans_x, trans_y, trans_z, rot_x, rot_y, rot_z]\n",
2581+
"motion_cols = [\"trans_x\", \"trans_y\", \"trans_z\", \"rot_x\", \"rot_y\", \"rot_z\"]\n",
2582+
"motion_params = motion_gt_df[motion_cols].to_numpy()\n",
2583+
"\n",
2584+
"plot_volumewise_motion(frames, motion_params)\n",
2585+
"\n",
2586+
"plt.tight_layout()\n",
2587+
"plt.show()"
2588+
],
2589+
"id": "1009ea77e1bdd0ee"
2590+
},
2591+
{
2592+
"metadata": {},
2593+
"cell_type": "markdown",
2594+
"source": "Let's plot the estimated and the ground truth framewise displacement.",
2595+
"id": "113b4b4d1361b5ec"
2596+
},
25522597
{
25532598
"cell_type": "code",
25542599
"execution_count": 18,
@@ -2565,9 +2610,10 @@
25652610
}
25662611
],
25672612
"source": [
2568-
"plt.figure(figsize=(18, 10))\n",
2569-
"sns.lineplot(x=\"Frame\", y=\"Framewise Displacement (mm)\", data=df_motion)\n",
2570-
"plt.title(\"Framewise Displacement (mm)\")\n",
2613+
"from nifreeze.viz.motion_viz import plot_framewise_displacement\n",
2614+
"\n",
2615+
"fd = pd.DataFrame({\"estimated\": estimated_fd, \"gt\": motion_gt_df[\"framewise_displacement\"].values})\n",
2616+
"plot_framewise_displacement(fd, labels=[\"Estimated\", \"Ground truth\"])\n",
25712617
"\n",
25722618
"plt.tight_layout()\n",
25732619
"plt.show()"

0 commit comments

Comments
 (0)