From 30df6e63942b5169c0642cf1695ef4ae4652faa5 Mon Sep 17 00:00:00 2001 From: Anton Rau Date: Fri, 4 Jun 2021 16:55:11 +0200 Subject: [PATCH] Per-channel normalization option in segmentation preprocessing. --- backend/histocat/core/segmentation/dto.py | 1 + .../processors/acquisition_processor.py | 13 +++++++++---- frontend/src/modules/segmentation/models.ts | 1 + .../segmentation/SegmentationSettingsView.vue | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/histocat/core/segmentation/dto.py b/backend/histocat/core/segmentation/dto.py index adb92470..f005f640 100644 --- a/backend/histocat/core/segmentation/dto.py +++ b/backend/histocat/core/segmentation/dto.py @@ -6,6 +6,7 @@ class SegmentationPreprocessingSettingsDto(BaseModel): """Segmentation preprocessing settings model.""" + channels_normalization: Optional[str] threshold: Optional[bool] percentile: Optional[float] normalize: bool diff --git a/backend/histocat/worker/segmentation/processors/acquisition_processor.py b/backend/histocat/worker/segmentation/processors/acquisition_processor.py index 2781e7fa..282a2f90 100644 --- a/backend/histocat/worker/segmentation/processors/acquisition_processor.py +++ b/backend/histocat/worker/segmentation/processors/acquisition_processor.py @@ -41,11 +41,16 @@ def process_acquisition( acquisition_data = parser.get_acquisition_data() nuclei_channels = acquisition_data.get_image_stack_by_names(params.nuclei_channels) - # nuclei_channels = normalize_by_zscore(nuclei_channels) - nuclei_channels = np.nanmean(nuclei_channels, axis=0) - cytoplasm_channels = acquisition_data.get_image_stack_by_names(params.cytoplasm_channels) - # cytoplasm_channels = normalize_by_zscore(cytoplasm_channels) + + if params.preprocessing.channels_normalization == "minmax": + nuclei_channels = normalize_by_minmax(nuclei_channels) + cytoplasm_channels = normalize_by_minmax(cytoplasm_channels) + elif params.preprocessing.channels_normalization == "zscore": + nuclei_channels = normalize_by_zscore(nuclei_channels) + cytoplasm_channels = normalize_by_zscore(cytoplasm_channels) + + nuclei_channels = np.nanmean(nuclei_channels, axis=0) cytoplasm_channels = np.nanmean(cytoplasm_channels, axis=0) # Combined together and expand to 4D diff --git a/frontend/src/modules/segmentation/models.ts b/frontend/src/modules/segmentation/models.ts index 3dbf8bc7..122dcec0 100644 --- a/frontend/src/modules/segmentation/models.ts +++ b/frontend/src/modules/segmentation/models.ts @@ -1,4 +1,5 @@ export interface ISegmentationPreprocessingSettings { + channels_normalization?: string; threshold?: boolean; percentile?: number; normalize: boolean; diff --git a/frontend/src/views/group/project/segmentation/SegmentationSettingsView.vue b/frontend/src/views/group/project/segmentation/SegmentationSettingsView.vue index 1e733ee2..24e78011 100644 --- a/frontend/src/views/group/project/segmentation/SegmentationSettingsView.vue +++ b/frontend/src/views/group/project/segmentation/SegmentationSettingsView.vue @@ -23,6 +23,11 @@ + + + + +