How to use the miscnn.processing.subfunctions.abstract_subfunction.Abstract_Subfunction function in miscnn

To help you get started, we’ve selected a few miscnn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frankkramer-lab / MIScnn / miscnn / processing / subfunctions / resize.py View on Github external
from batchgenerators.augmentations.utils import resize_segmentation
import numpy as np
# Internal libraries/scripts
from miscnn.processing.subfunctions.abstract_subfunction import Abstract_Subfunction

#-----------------------------------------------------#
#              Subfunction class: Resize              #
#-----------------------------------------------------#
""" A Resize Subfunction class which resizes an images according to a desired shape.

Methods:
    __init__                Object creation function
    preprocessing:          Resize imaging data to the desired shape
    postprocessing:         Resize a prediction to the desired shape
"""
class Resize(Abstract_Subfunction):
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self, new_shape=(128,128,128)):
        self.new_shape = new_shape
        self.original_shape = None

    #---------------------------------------------#
    #                Preprocessing                #
    #---------------------------------------------#
    def preprocessing(self, sample, training=True):
        # Access data
        img_data = sample.img_data
        seg_data = sample.seg_data
        # Cache current spacing for later postprocessing
        if not training : self.original_shape = (1,) + img_data.shape[0:-1]
github frankkramer-lab / MIScnn / miscnn / processing / subfunctions / padding.py View on Github external
""" A Padding Subfunction class which pads an images if required to a provided size.
    An image will only be padded, if its shape is smaller than the minimum size.

Args:
    min_size (tuple of integers):           Minimum shape of image. Every axis under this minimum size will be padded.
    pad_mode (string):                      Mode for padding. See in NumPy pad(array, mode="constant") documentation.
    pad_value_img (integer):                Value which will be used in padding mode "constant".
    pad_value_seg (integer):                Value which will be used in padding mode "constant".
    shape_must_be_divisible_by (integer):   Ensure that new shape is divisibly by provided number.

Methods:
    __init__                Object creation function
    preprocessing:          Padding to desired size of the imaging data
    postprocessing:         Cropping back to original size of the imaging data
"""
class Padding(Abstract_Subfunction):
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self, min_size, pad_mode="constant",
                 pad_value_img=0, pad_value_seg=0,
                 shape_must_be_divisible_by=None):
        self.min_size = min_size
        self.pad_mode = pad_mode
        self.pad_value_img = pad_value_img
        self.pad_value_seg = pad_value_seg
        self.shape_must_be_divisible_by = shape_must_be_divisible_by
        self.original_coords = None

    #---------------------------------------------#
    #                Preprocessing                #
    #---------------------------------------------#
github frankkramer-lab / MIScnn / miscnn / processing / subfunctions / resampling.py View on Github external
# Internal libraries/scripts
from miscnn.processing.subfunctions.abstract_subfunction import Abstract_Subfunction

#-----------------------------------------------------#
#            Subfunction class: Resampling            #
#-----------------------------------------------------#
""" A Resampling Subfunction class which resizes an images according to a desired voxel spacing.
    This function only works with already cached "spacing" matrix in the detailed information
    dictionary of the sample.

Methods:
    __init__                Object creation function
    preprocessing:          Resample to desired spacing between voxels in the imaging data
    postprocessing:         Resample to original spacing between voxels in the imaging data
"""
class Resampling(Abstract_Subfunction):
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self, new_spacing=(1,1,1)):
        self.new_spacing = new_spacing
        self.original_shape = None

    #---------------------------------------------#
    #                Preprocessing                #
    #---------------------------------------------#
    def preprocessing(self, sample, training=True):
        # Access data
        img_data = sample.img_data
        seg_data = sample.seg_data
        # Identify current spacing
        try : current_spacing = sample.details["spacing"]
github frankkramer-lab / MIScnn / miscnn / processing / subfunctions / clipping.py View on Github external
# External libraries
import numpy as np
# Internal libraries/scripts
from miscnn.processing.subfunctions.abstract_subfunction import Abstract_Subfunction

#-----------------------------------------------------#
#             Subfunction class: Clipping             #
#-----------------------------------------------------#
""" A Clipping Subfunction class which can be used for clipping intensity pixel values on a certain range.

Methods:
    __init__                Object creation function
    preprocessing:          Clipping the imaging data
    postprocessing:         Do nothing
"""
class Clipping(Abstract_Subfunction):
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self, min, max):
        self.min = min
        self.max = max

    #---------------------------------------------#
    #                Preprocessing                #
    #---------------------------------------------#
    def preprocessing(self, sample, training=True):
        # Access image
        image = sample.img_data
        # Perform clipping
        image_clipped = np.clip(image, self.min, self.max)
        # Update the sample with the normalized image
github frankkramer-lab / MIScnn / miscnn / processing / subfunctions / transform_HU.py View on Github external
import numpy as np
# Internal libraries/scripts
from miscnn.processing.subfunctions.abstract_subfunction import Abstract_Subfunction

#-----------------------------------------------------#
#            Subfunction class: TransformHU            #
#-----------------------------------------------------#
""" A function to scale CT raw data according to HU units .

Methods:
    __init__                Object creation function
    preprocessing:          Transforms CT raw data to HU .
    normalize_HU:           Normalizes HU values in a range between 0-1.
    postprocessing:         no postprocessing needed.
"""
class TransformHU(Abstract_Subfunction):
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self, normalize = True, slope = 1, intercept = -1024,
                 clipScan_value = -2000, minmaxBound = (-1000, 400)):
        """
            Args:
                    normalize (bool):       Normalizes HU units between 0-1 if True.
                    slope (float):          slope value derived from DICOM files.
                    intercept (float):      intercept value derived from DICOM files.
                    ClipScan_value (int):   sets scan values at clipping value to 0 (used for out of scan values).
                    minmaxBound (tuple):    Normalization boundaries.
        """
        self.normalize = normalize
        self.slope = slope
        self.intercept = intercept
github frankkramer-lab / MIScnn / miscnn / processing / subfunctions / normalization.py View on Github external
#-----------------------------------------------------#
#          Subfunction class: Normalization           #
#-----------------------------------------------------#
""" A Normalization Subfunction class which normalizes the intensity pixel values of an image using
    the Z-Score technique (default setting), through scaling to [0,1] or to grayscale [0,255].

Args:
    mode (string):          Mode which normalization approach should be performed.
                            Possible modi: "z-score", "minmax" or "grayscale"

Methods:
    __init__                Object creation function
    preprocessing:          Pixel intensity value normalization the imaging data
    postprocessing:         Do nothing
"""
class Normalization(Abstract_Subfunction):
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self, mode="z-score"):
        self.mode = mode

    #---------------------------------------------#
    #                Preprocessing                #
    #---------------------------------------------#
    def preprocessing(self, sample, training=True):
        # Access image
        image = sample.img_data
        # Perform z-score normalization
        if self.mode == "z-score":
            # Compute mean and standard deviation
            mean = np.mean(image)