From 0373e5e4eeed04ac5dcc574963d385a579ee38ab Mon Sep 17 00:00:00 2001 From: Friso Grace Date: Mon, 29 Jul 2024 16:17:55 +0200 Subject: [PATCH 1/4] Update segmentation loader to have reasonable values --- simpa_examples/segmentation_loader.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/simpa_examples/segmentation_loader.py b/simpa_examples/segmentation_loader.py index 8114ce0f..3138af90 100644 --- a/simpa_examples/segmentation_loader.py +++ b/simpa_examples/segmentation_loader.py @@ -19,11 +19,12 @@ @profile -def run_segmentation_loader(spacing: float | int = .1, path_manager=None, +def run_segmentation_loader(spacing: float | int = 1.0, input_spacing: float | int = 0.2, path_manager=None, visualise: bool = True): """ - :param spacing: The simulation spacing between voxels + :param spacing: The simulation spacing between voxels in mm + :param input_spacing: The input spacing between voxels in mm :param path_manager: the path manager to be used, typically sp.PathManager :param visualise: If VISUALIZE is set to True, the reconstruction result will be plotted :return: a run through of the example @@ -37,7 +38,6 @@ def run_segmentation_loader(spacing: float | int = .1, path_manager=None, label_mask = np.reshape(label_mask, (400, 1, 400)) - input_spacing = 0.2 segmentation_volume_tiled = np.tile(label_mask, (1, 128, 1)) segmentation_volume_mask = np.round(zoom(segmentation_volume_tiled, input_spacing/spacing, order=0)).astype(int) @@ -105,9 +105,11 @@ def segmentation_class_mapping(): if __name__ == "__main__": parser = ArgumentParser(description='Run the segmentation loader example') - parser.add_argument("--spacing", default=0.2, type=float, help='the voxel spacing in mm') + parser.add_argument("--spacing", default=1, type=float, help='the voxel spacing in mm') + parser.add_argument("--input_spacing", default=0.2, type=float, help='the input spacing in mm') parser.add_argument("--path_manager", default=None, help='the path manager, None uses sp.PathManager') parser.add_argument("--visualise", default=True, type=bool, help='whether to visualise the result') config = parser.parse_args() - run_segmentation_loader(spacing=config.spacing, path_manager=config.path_manager, visualise=config.visualise) + run_segmentation_loader(spacing=config.spacing, input_spacing=config.input_spacing, + path_manager=config.path_manager, visualise=config.visualise) From 88503b51bee4988517a1cc156fc492e81da519c6 Mon Sep 17 00:00:00 2001 From: Friso Grace Date: Tue, 30 Jul 2024 11:52:15 +0200 Subject: [PATCH 2/4] Now the segmentation loader should work with any spacing --- simpa_examples/segmentation_loader.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/simpa_examples/segmentation_loader.py b/simpa_examples/segmentation_loader.py index 3138af90..5f165392 100644 --- a/simpa_examples/segmentation_loader.py +++ b/simpa_examples/segmentation_loader.py @@ -7,6 +7,7 @@ import numpy as np from skimage.data import shepp_logan_phantom from scipy.ndimage import zoom +from skimage.transform import resize # FIXME temporary workaround for newest Intel architectures import os @@ -35,8 +36,8 @@ def run_segmentation_loader(spacing: float | int = 1.0, input_spacing: float | i label_mask = shepp_logan_phantom() label_mask = np.digitize(label_mask, bins=np.linspace(0.0, 1.0, 11), right=True) - - label_mask = np.reshape(label_mask, (400, 1, 400)) + label_mask = label_mask[100:300, 100:300] + label_mask = np.reshape(label_mask, (label_mask.shape[0], 1, label_mask.shape[1])) segmentation_volume_tiled = np.tile(label_mask, (1, 128, 1)) segmentation_volume_mask = np.round(zoom(segmentation_volume_tiled, input_spacing/spacing, @@ -67,9 +68,9 @@ def segmentation_class_mapping(): settings[Tags.RANDOM_SEED] = 1234 settings[Tags.WAVELENGTHS] = [700] settings[Tags.SPACING_MM] = spacing - settings[Tags.DIM_VOLUME_X_MM] = 400 / (spacing / input_spacing) - settings[Tags.DIM_VOLUME_Y_MM] = 128 / (spacing / input_spacing) - settings[Tags.DIM_VOLUME_Z_MM] = 400 / (spacing / input_spacing) + settings[Tags.DIM_VOLUME_X_MM] = segmentation_volume_mask.shape[0] * spacing + settings[Tags.DIM_VOLUME_Y_MM] = segmentation_volume_mask.shape[1] * spacing + settings[Tags.DIM_VOLUME_Z_MM] = segmentation_volume_mask.shape[2] * spacing settings.set_volume_creation_settings({ Tags.INPUT_SEGMENTATION_VOLUME: segmentation_volume_mask, From dce4af0c4fd2e8d98495ddc8c9ef3c4c4d8d94e9 Mon Sep 17 00:00:00 2001 From: Kris Dreher Date: Tue, 13 Aug 2024 13:42:31 +0200 Subject: [PATCH 3/4] Added only essential examples to benchmarking scripts --- simpa_examples/benchmarking/performance_check.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simpa_examples/benchmarking/performance_check.py b/simpa_examples/benchmarking/performance_check.py index 2f969837..f933f2de 100644 --- a/simpa_examples/benchmarking/performance_check.py +++ b/simpa_examples/benchmarking/performance_check.py @@ -28,10 +28,10 @@ def run_benchmarking_tests(spacing=0.4, profile: str = "TIME", savefolder: str = import simpa_examples - examples = [simpa_examples.run_linear_unmixing, simpa_examples.run_minimal_optical_simulation, - simpa_examples.run_minimal_optical_simulation_uniform_cube, simpa_examples.run_msot_invision_simulation, + examples = [simpa_examples.run_minimal_optical_simulation, + simpa_examples.run_minimal_optical_simulation_uniform_cube, simpa_examples.run_optical_and_acoustic_simulation, - simpa_examples.run_perform_iterative_qPAI_reconstruction, simpa_examples.run_segmentation_loader] + simpa_examples.run_segmentation_loader] for example in examples: example(spacing=spacing, path_manager=None, visualise=False) From ab013ae9b371438f855760aedb6e7db48b451c5d Mon Sep 17 00:00:00 2001 From: Kris Dreher Date: Tue, 13 Aug 2024 13:43:27 +0200 Subject: [PATCH 4/4] Changed default spacing in benchmarking --- docs/source/benchmarking.md | 2 +- simpa_examples/benchmarking/run_benchmarking.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/benchmarking.md b/docs/source/benchmarking.md index dbfa1d8f..669ccfc1 100644 --- a/docs/source/benchmarking.md +++ b/docs/source/benchmarking.md @@ -45,7 +45,7 @@ Please put this in the conversation of the pull request, and not add it to the f ## Default Values If no options are provided for initial spacing, final spacing, or step size, the script uses the following default values: -- **Initial Spacing**: 0.15mm +- **Initial Spacing**: 0.2mm - **Final Spacing**: 0.25mm - **Step Size**: 0.05mm diff --git a/simpa_examples/benchmarking/run_benchmarking.sh b/simpa_examples/benchmarking/run_benchmarking.sh index b9757194..0659d932 100644 --- a/simpa_examples/benchmarking/run_benchmarking.sh +++ b/simpa_examples/benchmarking/run_benchmarking.sh @@ -8,7 +8,7 @@ echo "For further details see readme" echo "Number of examples can be selected in performance_check.py" echo "For comparable benchmarks, please use default" echo "Options:" -echo " -i, --init First spacing to benchmark: default = 0.15mm" +echo " -i, --init First spacing to benchmark: default = 0.2mm" echo " -c, --cease Final spacing to benchmark: default = 0.25mm" echo " -s, --step Step between spacings: default = 0.05mm" echo " -f, --file Where to store the output files: default save in current directory; 'print' prints it in console" @@ -59,7 +59,7 @@ shift 1 done if [ "$start" == 0 ]; then - start=0.15 + start=0.2 fi if [ "$stop" == 0 ]; then