pyalfe.tasks.segmentation#
- class pyalfe.tasks.segmentation.Segmentation(inference_model: InferenceModel, image_processor: ImageProcessor)[source]#
Bases:
Task
This is the parent class for segmentation tasks.
- predict(images: list[str | Path] | tuple[str | Path], pred: str | Path)[source]#
Creates a prediction image given the input images.
- Parameters:
images (list[str or Path] or tuple[str or Path]) – A list or tuple of input images.
pred (list[str or Path]) – Path to the output prediction segmentation image.
- post_process(pred, seg, mask=None)[source]#
Post processes the prediction segmentation image by applying an optional mask to create the final segmentation. For example, in a lesion segmentation task you can remove any lesion outside the brain by applying a brain mask.
- Parameters:
pred (str or Path) – Path to the prediction segmentation image.
mask (str or Path) – Path to the mask image.
seg (str or Path) – Path to the output post-processed segmentation image.
- class pyalfe.tasks.segmentation.MultiModalitySegmentation(inference_model: InferenceModel, image_processor: ImageProcessor, pipeline_dir: PipelineDataDir, modality_list: list[str], output_modality: str, image_type_input: str = 'skullstripped', image_type_output: str = 'abnormal_seg', image_type_mask: str | None = None, segmentation_dir: str = 'abnormalmap', components: bool = False, overwrite: bool = True)[source]#
Bases:
Segmentation
This task generates a segmentation from several input modalities.
- Parameters:
inference_model (InferenceModel) – The inference model object.
image_processor (ImageProcessor) – The image processor object.
pipeline_dir (PipelineDataDir) – The pipeline data directory object.
modality_list (list[Modality]) – The modalities used for segmentation. For example, [T1, T1Post].
output_modality (Modality) – The modality where the segmentation output will be saved in its directory.
image_type_input (str = 'skullstripped') – The type of image that should be used as input. Default is skullstripped.
image_type_output (str) – The type of output image that segmentation should be saved as. Default is abnormal_seg.
image_type_mask (str = None) – The type of output image modality that should be used as a mask. Default is None.
segmentation_dir (str = 'abnormalmap') – The directory where the segmentaiton should be saved into. Default is abnormalmap.
components (bool = False) – If True, creates a segmentation image that separately labels all the connected components of the original segmentation. Default is False.
overwrite (bool = True) – Whether to overwrite existing output segmentation images. Default is True.
- logger = <Logger MultiModalitySegmentation (DEBUG)>#
- class pyalfe.tasks.segmentation.SingleModalitySegmentation(inference_model: InferenceModel, image_processor: ImageProcessor, pipeline_dir: PipelineDataDir, modality, image_type_input: str = 'skullstripped', image_type_output: str = 'abnormal_seg', image_type_mask: str | None = None, segmentation_dir: str = 'abnormalmap', components: bool = False, overwrite: bool = True)[source]#
Bases:
MultiModalitySegmentation
This task generates a segmentation from a single input modality.
Parameters
- image_processor: ImageProcessor
The image processor object.
- pipeline_dir: PipelineDataDir
The pipeline data directory object.
- modality: Modality
The modality used for segmentation. For example, [T1, T1Post].
- image_type_input: str = ‘skullstripped’
The type of image that should be used as input. Default is skullstripped.
- image_type_output: str
The type of output image that segmentation should be saved as. Default is abnormal_seg.
- image_type_mask: str = None
The type of output image modality that should be used as a mask. Default is None.
- segmentation_dir: str = ‘abnormalmap’
The directory where the segmentaiton should be saved into. Default is abnormalmap.
- components: bool = False
If True, creates a segmentation image that separately labels all the connected components of the original segmentation. Default is False.
- overwrite: bool = True
Whether to overwrite existing output segmentation images. Default is True.
- logger = <Logger SingleModalitySegmentation (DEBUG)>#
- class pyalfe.tasks.segmentation.TissueWithPriorSegementation(inference_model: InferenceModel, image_processor: ImageProcessor, pipeline_dir: PipelineDataDir, image_type_input: str = 'trim_upsampled', image_type_output: str = 'tissue_seg', template_name: str = 'Tissue', overwrite: bool = True)[source]#
Bases:
Segmentation
This task generates tissue segmentation from T1 and a prior atlas based segementation.
- Parameters:
inference_model (InferenceModel) – The inference model object.
image_processor (ImageProcessor) – The image processor object.
pipeline_dir (PipelineDataDir) – The pipeline data directory object.
image_type_input (str = 'skullstripped') – The type of image that should be used as input. Default is skullstripped.
image_type_output (str) – The type of output image that segmentation should be saved as. Default is tissue_seg.
overwrite (bool = True) – Whether to overwrite existing output segmentation images. Default is True.
- logger = <Logger TissueWithPriorSegementation (DEBUG)>#
- class pyalfe.tasks.segmentation.SynthSegTissueSegmentation(inference_model: InferenceModel, image_processor: ImageProcessor, pipeline_dir: PipelineDataDir, image_type_input: str = 'trim_upsampled', image_type_output: str = 'tissue_seg', overwrite: bool = True)[source]#
Bases:
Segmentation
This task generates tissue segmentation using freesurfer’s synthseg
- Parameters:
inference_model (InferenceModel) – The inference model object.
image_processor (ImageProcessor) – The image processor object.
pipeline_dir (PipelineDataDir) – The pipeline data directory object.
image_type_input (str = 'skullstripped') – The type of image that should be used as input. Default is skullstripped.
image_type_output (str) – The type of output image that segmentation should be saved as. Default is tissue_seg.
overwrite (bool = True) – Whether to overwrite existing output segmentation images. Default is True.
- logger = <Logger SynthSegTissueSegmentation (DEBUG)>#
- post_process(pred, seg, mask=None)[source]#
Post processes the prediction segmentation image by applying an optional mask to create the final segmentation. For example, in a lesion segmentation task you can remove any lesion outside the brain by applying a brain mask.
- Parameters:
pred (str or Path) – Path to the prediction segmentation image.
mask (str or Path) – Path to the mask image.
seg (str or Path) – Path to the output post-processed segmentation image.