Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update segmentation loader to have reasonable values #366

Merged
merged 13 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions simpa_examples/benchmarking/performance_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions simpa_examples/benchmarking/run_benchmarking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -59,7 +59,7 @@ shift 1
done

if [ "$start" == 0 ]; then
start=0.15
start=0.2
fi

if [ "$stop" == 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion simpa_examples/msot_invision_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_settings():
}

acoustic_settings = {
Tags.ACOUSTIC_SIMULATION_3D: True,
Tags.ACOUSTIC_SIMULATION_3D: False,
Tags.ACOUSTIC_MODEL_BINARY_PATH: path_manager.get_matlab_binary_path(),
Tags.KWAVE_PROPERTY_ALPHA_POWER: 0.00,
Tags.KWAVE_PROPERTY_SENSOR_RECORD: "p",
Expand Down
23 changes: 13 additions & 10 deletions simpa_examples/segmentation_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,11 +20,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
Expand All @@ -34,10 +36,9 @@ def run_segmentation_loader(spacing: float | int = .1, path_manager=None,
label_mask = shepp_logan_phantom()

label_mask = np.digitize(label_mask, bins=np.linspace(0.0, 1.0, 11), right=True)
label_mask = label_mask[100:300, 100:300]
label_mask = np.reshape(label_mask, (label_mask.shape[0], 1, label_mask.shape[1]))

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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -105,9 +106,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)
Loading