StrokeSegLab
Loading...
Searching...
No Matches
StrokeSegLab.postprocessing.postprocessor.Postprocessor Class Reference

Public Member Functions

None __init__ (self, gui=None)
 
None check_viewer (self, str viewer)
 
None run (self, np.ndarray data, np.ndarray affine, str input_path, list[tuple[int, int]] bbox, tuple[int, int, int] original_shape, str temp_dir, str trsf_path, tuple[float, float, float] old_spacing, list[tuple[int, int]] padding, str bet, str MNI_base_image, float threshold, bool open_viewer=False)
 

Public Attributes

 option = Option()
 
 logger = logging.getLogger()
 
 wrapper = AnimaWrapper()
 
 resampler = Resampler()
 
 config = Config()
 
 viewer = Viewer()
 
 gui = gui
 

Protected Member Functions

str _save_img (self, str temp_dir, np.ndarray data, str base_name, np.ndarray affine, str name)
 
tuple[np.ndarray, np.ndarray] _convert_to_segmentation (self, np.ndarray data, float threshold)
 
None _register_seg_to_reference (self, str img_path, str trsf_path, str ref)
 
None _binarize_seg (self, str seg_path, float threshold=0.5)
 
None _print_action (self, str action_name)
 
np.ndarray _remove_padding (self, np.ndarray data, list[tuple[int, int]] padding)
 
np.ndarray _uncrop_from_bbox (self, np.ndarray data, tuple[slice, slice, slice] slicer, tuple[int, int, int] original_shape)
 

Detailed Description

This class performs postprocessing on 3D images

Constructor & Destructor Documentation

◆ __init__()

None StrokeSegLab.postprocessing.postprocessor.Postprocessor.__init__ ( self,
gui = None )
Initialize the main postprocessing class with optional GUI integration.

Args:
    gui (GUIMain, optional): Instance of the gui class to enable the display of messages and status updates. Defaults to None.

Member Function Documentation

◆ _binarize_seg()

None StrokeSegLab.postprocessing.postprocessor.Postprocessor._binarize_seg ( self,
str seg_path,
float threshold = 0.5 )
protected
@public
Convert float segmentation into a binary mask (0 / 1).

◆ _convert_to_segmentation()

tuple[np.ndarray,np.ndarray] StrokeSegLab.postprocessing.postprocessor.Postprocessor._convert_to_segmentation ( self,
np.ndarray data,
float threshold )
protected
@public
Convert the output of the model into a segmentation based on the threshold given : 
- Take the first element of the batch axis
- Apply a softmax on the channel dimensions (2 channels : background and lesion)
- Exctract the probabilities of the lesion class (1)
- Save it if the option 'pmap' is specified
- Apply a threshold to create a binary mask

Args:
    data (np.ndarray): Model output with shape (batch_size, channels, x, y, z)
    threshold (float): Threshold to create the binary mask

Returns:
    tuple[np.ndarray,np.ndarray]: seg : binary mask, pmap : probability map if requested

◆ _print_action()

None StrokeSegLab.postprocessing.postprocessor.Postprocessor._print_action ( self,
str action_name )
protected
@public
Log the current action
Args:
    action_name (str): Name of the action

◆ _register_seg_to_reference()

None StrokeSegLab.postprocessing.postprocessor.Postprocessor._register_seg_to_reference ( self,
str img_path,
str trsf_path,
str ref )
protected
@public
Register a segmentation to a reference using Anima.
Applies a binarization step afterward to remove float interpolation artifacts.

◆ _remove_padding()

np.ndarray StrokeSegLab.postprocessing.postprocessor.Postprocessor._remove_padding ( self,
np.ndarray data,
list[tuple[int, int]] padding )
protected
@public
Remove padding from a numpy array based on a list of tuples specifying the intervals to keep for each dimension

Args:
    data (np.ndarray): Data numpy array to process
    padding (list[tuple[int, int]]): List of tuples that specify the padding to remove (start, end)

Returns:
    np.ndarray: Array with padding removed

◆ _save_img()

str StrokeSegLab.postprocessing.postprocessor.Postprocessor._save_img ( self,
str temp_dir,
np.ndarray data,
str base_name,
np.ndarray affine,
str name )
protected
@public
Save a NIFTI image with a dynamically constructed name

Args:
    temp_dir (str): Directory where the image will be save
    data (np.ndarray): Data of the image 
    base_name (str): Basename of the image, without extension
    affine (np.ndarray): Affine transformation matrix of the image
    name (str): Identifier to determine filename suffix

Returns:
    str: Full path of the saved file

◆ _uncrop_from_bbox()

np.ndarray StrokeSegLab.postprocessing.postprocessor.Postprocessor._uncrop_from_bbox ( self,
np.ndarray data,
tuple[slice,slice,slice] slicer,
tuple[int,int,int] original_shape )
protected
@public
Place the cropped data back into a full-size volume at the location specified by slicer. Then transpose the volume axes from (x, y, z) to (z, y, x)

Args:
    data (np.ndarray): Cropped data
    slicer (tuple[slice,slice,slice]): Tuple of slices that specify where to place data
    original_shape (tuple[int,int,int]): Shape of full original volume

Returns:
    np.ndarray: Uncropped data

◆ check_viewer()

None StrokeSegLab.postprocessing.postprocessor.Postprocessor.check_viewer ( self,
str viewer )
Call for check_viewer method from the viewer class to check if the viewer specify exist

Args:
    viewer (str): Name of the viewer specify

◆ run()

None StrokeSegLab.postprocessing.postprocessor.Postprocessor.run ( self,
np.ndarray data,
np.ndarray affine,
str input_path,
list[tuple[int, int]] bbox,
tuple[int,int,int] original_shape,
str temp_dir,
str trsf_path,
tuple[float,float,float] old_spacing,
list[tuple[int, int]] padding,
str bet,
str MNI_base_image,
float threshold,
bool open_viewer = False )
Run the entire postprocessing pipeline on the data produced by the inference step : 
- Convert to segmentation, return a pmap if the option is specified by the user
- Remove padding
- Uncrop
- Resampling to the original spacing
- Saving image
- Register to reference only if the inverse transformation was applied during preprocessing
- Open viewer with input image and binary mask if the option was specified by the user


Args:
    data (np.ndarray): Data prostprocessed
    affine (np.ndarray): affine matrix
    input_path (str): Input path
    bbox (list[tuple[int, int]]): Bounding box coordinates used for cropping
    original_shape (tuple[int,int,int]): Original shape of the image before preprocessing
    temp_dir (str): Path to the temporary directory
    trsf_path (str): Path to the transformation text file
    old_spacing (tuple[float,float,float]): Voxel spacing of the input image
    padding (list[tuple[int, int]]): List of padding tuples applied to each dimension
    bet (str): Path to the brain-extracted T1 image
    MNI_base_image (str): Reference MNI image array or None
    threshold (float): Segmentation threshold value
    open_viewer (bool, optional): If True open a viewer with input image and segmentation. Defaults to False.

The documentation for this class was generated from the following file: