Skip to content

Sf base

Subfunction_Base ¤

Bases: ABC

An abstract base class for a Subfunction class.

A child of this ABC can be used as a Subfunction and be passed to a DataGenerator.

This class provides functionality for running the transform function, which preprocesses an image during the processing (batch preparation) of the DataGenerator.

Create a custom Subfunction
from aucmedi.data_processing.subfunctions.sf_base import Subfunction_Base

class My_custom_Subfunction(Subfunction_Base):
    def __init__(self):                 # you can pass here class variables
        pass

    def transform(self, image):
        new_image = image + 1.0         # do some operation
        return new_image                # return modified image
Required Functions
Function Description
__init__() Object creation function.
transform() Transform the image.
Source code in aucmedi/data_processing/subfunctions/sf_base.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Subfunction_Base(ABC):
    """ An abstract base class for a Subfunction class.

    A child of this ABC can be used as a [Subfunction][aucmedi.data_processing.subfunctions]
    and be passed to a [DataGenerator][aucmedi.data_processing.data_generator.DataGenerator].

    This class provides functionality for running the transform function,
    which preprocesses an image during the processing (batch preparation) of the DataGenerator.

    ???+ example "Create a custom Subfunction"
        ```python
        from aucmedi.data_processing.subfunctions.sf_base import Subfunction_Base

        class My_custom_Subfunction(Subfunction_Base):
            def __init__(self):                 # you can pass here class variables
                pass

            def transform(self, image):
                new_image = image + 1.0         # do some operation
                return new_image                # return modified image
        ```

    ???+ info "Required Functions"
        | Function            | Description                                |
        | ------------------- | ------------------------------------------ |
        | `__init__()`        | Object creation function.                  |
        | `transform()`       | Transform the image.                       |

    """
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    @abstractmethod
    def __init__(self):
        """ Functions which will be called during the Subfunction object creation.

        This function can be used to pass variables and options in the Subfunction instance.
        The are no mandatory required parameters for the initialization.
        """
        pass
    #---------------------------------------------#
    #                Transformation               #
    #---------------------------------------------#
    @abstractmethod
    def transform(self, image):
        """ Transform the image according to the subfunction during preprocessing (training + prediction).

        It is required to return the transformed image object (as NumPy array).

        Args:
            image (numpy.ndarray):      Image encoded as NumPy matrix with 1 or 3 channels. (e.g. 224x224x3)

        Returns:
            image (numpy.ndarray):      Transformed image encoded as NumPy matrix with 1 or 3 channels. (e.g. 224x224x3)
        """
        return image

__init__() abstractmethod ¤

Functions which will be called during the Subfunction object creation.

This function can be used to pass variables and options in the Subfunction instance. The are no mandatory required parameters for the initialization.

Source code in aucmedi/data_processing/subfunctions/sf_base.py
60
61
62
63
64
65
66
67
@abstractmethod
def __init__(self):
    """ Functions which will be called during the Subfunction object creation.

    This function can be used to pass variables and options in the Subfunction instance.
    The are no mandatory required parameters for the initialization.
    """
    pass

transform(image) abstractmethod ¤

Transform the image according to the subfunction during preprocessing (training + prediction).

It is required to return the transformed image object (as NumPy array).

Parameters:

Name Type Description Default
image numpy.ndarray

Image encoded as NumPy matrix with 1 or 3 channels. (e.g. 224x224x3)

required

Returns:

Name Type Description
image numpy.ndarray

Transformed image encoded as NumPy matrix with 1 or 3 channels. (e.g. 224x224x3)

Source code in aucmedi/data_processing/subfunctions/sf_base.py
71
72
73
74
75
76
77
78
79
80
81
82
83
@abstractmethod
def transform(self, image):
    """ Transform the image according to the subfunction during preprocessing (training + prediction).

    It is required to return the transformed image object (as NumPy array).

    Args:
        image (numpy.ndarray):      Image encoded as NumPy matrix with 1 or 3 channels. (e.g. 224x224x3)

    Returns:
        image (numpy.ndarray):      Transformed image encoded as NumPy matrix with 1 or 3 channels. (e.g. 224x224x3)
    """
    return image