|
2480 | 2480 | " motion_parameters.append([tx, ty, tz, rx, ry, rz])\n",
|
2481 | 2481 | "\n",
|
2482 | 2482 | "motion_parameters = np.array(motion_parameters)\n",
|
2483 |
| - "fd = compute_fd(motion_parameters)\n", |
| 2483 | + "estimated_fd = compute_fd(motion_parameters)\n", |
2484 | 2484 | "\n",
|
2485 | 2485 | "# Creating a DataFrame for better visualization\n",
|
2486 | 2486 | "df_motion = pd.DataFrame(\n",
|
2487 | 2487 | " {\n",
|
2488 |
| - " \"Frame\": np.arange(len(fd)),\n", |
| 2488 | + " \"Frame\": np.arange(len(estimated_fd)),\n", |
2489 | 2489 | " \"Translation X\": motion_parameters[:, 0],\n",
|
2490 | 2490 | " \"Translation Y\": motion_parameters[:, 1],\n",
|
2491 | 2491 | " \"Translation Z\": motion_parameters[:, 2],\n",
|
2492 | 2492 | " \"Rotation X\": motion_parameters[:, 3],\n",
|
2493 | 2493 | " \"Rotation Y\": motion_parameters[:, 4],\n",
|
2494 | 2494 | " \"Rotation Z\": motion_parameters[:, 5],\n",
|
2495 |
| - " \"Framewise Displacement (mm)\": fd,\n", |
| 2495 | + " \"Framewise Displacement (mm)\": estimated_fd,\n", |
2496 | 2496 | " }\n",
|
2497 | 2497 | ")"
|
2498 | 2498 | ]
|
|
2549 | 2549 | "plt.show()"
|
2550 | 2550 | ]
|
2551 | 2551 | },
|
| 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 | + }, |
2552 | 2597 | {
|
2553 | 2598 | "cell_type": "code",
|
2554 | 2599 | "execution_count": 18,
|
|
2565 | 2610 | }
|
2566 | 2611 | ],
|
2567 | 2612 | "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", |
2571 | 2617 | "\n",
|
2572 | 2618 | "plt.tight_layout()\n",
|
2573 | 2619 | "plt.show()"
|
|
0 commit comments