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

T 371 segmentation loader with multiple wavelengths #372

Merged
merged 4 commits into from
Aug 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from simpa.core.simulation_modules.volume_creation_module import VolumeCreationAdapterBase
from simpa.utils import Tags
from simpa.utils.constants import property_tags
from simpa.io_handling import save_hdf5
import numpy as np
import torch

Expand Down Expand Up @@ -44,21 +42,19 @@ def create_simulation_volume(self) -> dict:

for seg_class in segmentation_classes:
class_properties = class_mapping[seg_class].get_properties_for_wavelength(self.global_settings, wavelength)
for prop_tag in property_tags:
if isinstance(class_properties[prop_tag], (int, float)) or class_properties[prop_tag] == None: # scalar
assigned_prop = class_properties[prop_tag]
for volume_key in volumes.keys():
if isinstance(class_properties[volume_key], (int, float)) or class_properties[volume_key] == None: # scalar
assigned_prop = class_properties[volume_key]
if assigned_prop is None:
assigned_prop = torch.nan
volumes[prop_tag][segmentation_volume == seg_class] = assigned_prop
elif len(torch.Tensor.size(class_properties[prop_tag])) == 3: # 3D map
assigned_prop = class_properties[prop_tag][torch.tensor(segmentation_volume == seg_class)]
volumes[volume_key][segmentation_volume == seg_class] = assigned_prop
elif len(torch.Tensor.size(class_properties[volume_key])) == 3: # 3D map
assigned_prop = class_properties[volume_key][torch.tensor(segmentation_volume == seg_class)]
assigned_prop[assigned_prop is None] = torch.nan
volumes[prop_tag][torch.tensor(segmentation_volume == seg_class)] = assigned_prop
volumes[volume_key][torch.tensor(segmentation_volume == seg_class)] = assigned_prop
else:
raise AssertionError("Properties need to either be a scalar or a 3D map.")

save_hdf5(self.global_settings, self.global_settings[Tags.SIMPA_OUTPUT_PATH], "/settings/")

# convert volumes back to CPU
for key in volumes.keys():
volumes[key] = volumes[key].numpy().astype(np.float64, copy=False)
Expand Down
2 changes: 1 addition & 1 deletion simpa_examples/segmentation_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def segmentation_class_mapping():
settings[Tags.SIMULATION_PATH] = path_manager.get_hdf5_file_save_path()
settings[Tags.VOLUME_NAME] = "SegmentationTest"
settings[Tags.RANDOM_SEED] = 1234
settings[Tags.WAVELENGTHS] = [700]
settings[Tags.WAVELENGTHS] = [700, 800]
settings[Tags.SPACING_MM] = 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
Expand Down
Loading