Skip to content

Layers

Layers are the fundamental blocks of Hocrox.

In Hocrox, each layer basically a function that will be performed on the images to preprocess or augment the image.

Currently, in Hocrox, there are several supported layers. The complete list is below.

  • Save
  • Read
  • Preprocessing
    • Blur
      • AverageBlur
      • GaussianBlur
      • MedianBlur
      • BilateralBlur
    • Color
      • Brightness
      • ChannelShift
      • Grayscale
      • Rescale
    • Flip
      • Horizontal Flip
      • Vertical Flip
    • Shift
      • Horizontal Shift
      • Vertical Shift
    • Transformation
      • Crop
      • Padding
      • Resize
      • Rotate
      • Convolution
  • Augmentation
    • Color
      • RandomBrightness
      • RandomChannelShift
    • Flip
      • RandomVerticalFlip
      • RandomHorizontalFlip
      • RandomFlip
    • Shift
      • RandomHorizontalShift
      • RandomVerticalShift
    • Transformation
      • RandomRotate
      • RandomZoom

augmentation special

Image Augmentation is the process of modifying existing images and creating multiple copies of it, hence increasing total number of images.

In image Augmentation, we slightly rotate, flip, change the color of the images to generate multiple versions of the image. Since all these images are from the original image with slight modifications, they still represent the original patterns from the original images (most of the time).

color special

Augmentation layers that manupulate the color of an image in some way.

random_brightness

RandomBrightness layer for Hocrox.

RandomBrightness (Layer)

RandomBrightness layer randomly changes the brightness of the image based on the provided low and high.

Here is an example code to use the RandomBrightness layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.color import RandomBrightness
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomBrightness(low=0.5, high=3.0, probability=1.0, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, low=0.5, high=3.0, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomBrightness layer.

Parameters:

Name Type Description Default
low float

Starting range of the brightness. Defaults to 0.5.

0.5
high float

Ending range of the brightness. Defaults to 3.0.

3.0
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the low parameter is not valid

ValueError

If the high parameter is not valid

ValueError

If the probability parameter is not valid

ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/color/random_brightness.py
def __init__(self, low=0.5, high=3.0, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomBrightness layer.

    Args:
        low (float, optional): Starting range of the brightness. Defaults to 0.5.
        high (float, optional): Ending range of the brightness. Defaults to 3.0.
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the low parameter is not valid
        ValueError: If the high parameter is not valid
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_images parameter is not valid
    """
    if not (isinstance(low, float)):
        raise ValueError(f"The value {low} for the argument low is not valid")

    if not (isinstance(high, float)):
        raise ValueError(f"The value {high} for the argument high is not valid")

    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_brightness",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Low: {low}, High:{high}, Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__low = low
    self.__high = high
    self.__probability = probability

random_channel_shift

RandomChannelShift layer for Hocrox.

RandomChannelShift (Layer)

RandomChannelShift layer randomly adds some value to the channels in the image.

Here is an example code to use the RandomChannelShift layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.color import RandomChannelShift
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomChannelShift(low=1, high=5, probability=1.0, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, low=1, high=5, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomChannelShift layer.

Parameters:

Name Type Description Default
low int

Starting range of the brightness. Defaults to 0.5.

1
high int

Ending range of the brightness. Defaults to 3.0.

5
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the low parameter is not valid

ValueError

If the high parameter is not valid

ValueError

If the probability parameter is not valid

ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/color/random_channel_shift.py
def __init__(self, low=1, high=5, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomChannelShift layer.

    Args:
        low (int, optional): Starting range of the brightness. Defaults to 0.5.
        high (int, optional): Ending range of the brightness. Defaults to 3.0.
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the low parameter is not valid
        ValueError: If the high parameter is not valid
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_images parameter is not valid
    """
    if not (isinstance(low, int)):
        raise ValueError(f"The value {low} for the argument low is not valid")

    if not (isinstance(high, int)):
        raise ValueError(f"The value {high} for the argument high is not valid")

    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_channel_shift",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Low: {low}, High:{high}, Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__low = low
    self.__high = high
    self.__probability = probability

flip special

Augmentation layers that flips image vertically or horizontally.

random_flip

RandomFlip layer for Hocrox.

RandomFlip (Layer)

RandomFlip layer randomly flips an image vertically or horizontally.

Here is an example code to use the RandomFlip layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.flip import RandomFlip
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomFlip(number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomFlip layer.

Parameters:

Name Type Description Default
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the probability parameter is not valid

ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/flip/random_flip.py
def __init__(self, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomFlip layer.

    Args:
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_images parameter is not valid
    """
    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_flip",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__probability = probability

random_horizontal_flip

RandomHorizontalFlip layer for Hocrox.

RandomHorizontalFlip (Layer)

RandomHorizontalFlip layer randomly flips an image horizontally.

Here is an example code to use the RandomHorizontalFlip layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.flip import RandomHorizontalFlip
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomHorizontalFlip(probability=1.0, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomHorizontalFlip layer.

Parameters:

Name Type Description Default
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the probability parameter is not valid

ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/flip/random_horizontal_flip.py
def __init__(self, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomHorizontalFlip layer.

    Args:
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_images parameter is not valid
    """
    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_horizontal_flip",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__probability = probability

random_vertical_flip

RandomVerticalFlip layer for Hocrox.

RandomVerticalFlip (Layer)

RandomVerticalFlip layer randomly flips an image vertically.

Here is an example code to use the RandomVerticalFlip layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.flip import RandomVerticalFlip
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomVerticalFlip(number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomVerticalFlip layer.

Parameters:

Name Type Description Default
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/flip/random_vertical_flip.py
def __init__(self, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomVerticalFlip layer.

    Args:
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the number_of_images parameter is not valid
    """
    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_vertical_flip",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__probability = probability

shift special

Augmentation layers that shifts image vertically or horizontally.

random_horizontal_shift

RandomHorizontalShift layer for Hocrox.

RandomHorizontalShift (Layer)

RandomHorizontalShift layer randomly shifts an image horizontally.

Here is an example code to use the RandomHorizontalShift layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.shift import RandomHorizontalShift
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomHorizontalShift(ratio=0.7, probability=1.0, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, ratio=0.7, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomHorizontalShift layer.

Parameters:

Name Type Description Default
ratio float

Ratio is used to define the range of the shift. Defaults to 0.7.

0.7
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the ratio parameter is not valid

ValueError

If the probability parameter is not valid

ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/shift/random_horizontal_shift.py
def __init__(self, ratio=0.7, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomHorizontalShift layer.

    Args:
        ratio (float, optional): Ratio is used to define the range of the shift. Defaults to 0.7.
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the ratio parameter is not valid
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_images parameter is not valid
    """
    if not (isinstance(ratio, float)):
        raise ValueError(f"The value {ratio} for the argument ratio is not valid")

    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_horizontal_shift",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Ratio:{ratio}, Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__ratio = ratio
    self.__probability = probability

random_vertical_shift

RandomVerticalShift layer for Hocrox.

RandomVerticalShift (Layer)

RandomVerticalShift layer randomly shifts the image vertically.

Here is an example code to use the RandomVerticalShift layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.shift import RandomVerticalShift
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomVerticalShift(ratio=0.7, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, ratio=0.7, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomVerticalShift layer.

Parameters:

Name Type Description Default
ratio float

Ratio is used to define the range of the shift. Defaults to 0.7.

0.7
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the ratio parameter is not valid

ValueError

If the probability parameter is not valid

ValueError

If the number_of_images parameter is not valid

Source code in hocrox/layer/augmentation/shift/random_vertical_shift.py
def __init__(self, ratio=0.7, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomVerticalShift layer.

    Args:
        ratio (float, optional): Ratio is used to define the range of the shift. Defaults to 0.7.
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the ratio parameter is not valid
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_images parameter is not valid
    """
    if not (isinstance(ratio, float)):
        raise ValueError(f"The value {ratio} for the argument ratio is not valid")

    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_vertical_shift",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Ratio:{ratio}, Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__ratio = ratio
    self.__probability = probability

transformation special

Augmentation layers that transformatios image in different ways.

random_rotate

RandomRotate layer for Hocrox.

RandomRotate (Layer)

RandomRotate layer randomly rotates an image to a certain angle.

Here is an example code to use the RandomRotate layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.transformation import RandomRotate
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomRotate(start_angle=-10.0, end_angle=10.0, number_of_outputs=5))

# Printing the summary of the model
print(model.summary())
__init__(self, start_angle, end_angle, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomRotate layer.

Parameters:

Name Type Description Default
start_angle float

Start of the range of angle

required
end_angle float

End of the range of angle

required
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the start_angle parameter is not valid

ValueError

If the end_angle parameter is not valid

ValueError

If the probability parameter is not valid

ValueError

If the number_of_outputs parameter is not valid

Source code in hocrox/layer/augmentation/transformation/random_rotate.py
def __init__(self, start_angle, end_angle, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomRotate layer.

    Args:
        start_angle (float): Start of the range of angle
        end_angle (float): End of the range of angle
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the start_angle parameter is not valid
        ValueError: If the end_angle parameter is not valid
        ValueError: If the probability parameter is not valid
        ValueError: If the number_of_outputs parameter is not valid
    """
    if not (isinstance(start_angle, int) or isinstance(start_angle, float)):
        raise ValueError(f"The value {start_angle} for the argument start_angle is not valid")

    if not (isinstance(end_angle, int) or isinstance(end_angle, float)):
        raise ValueError(f"The value {end_angle} for the argument end_angle is not valid")

    if start_angle > end_angle:
        raise ValueError(f"The value {start_angle} for the argument start_angle is not valid")

    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    self.__start_angle = start_angle
    self.__end_angle = end_angle
    self.__probability = probability
    self.__number_of_outputs = number_of_outputs

    super().__init__(
        name,
        "random_rotate",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

random_zoom

RandomZoom layer for Hocrox.

RandomZoom (Layer)

RandomZoom layer randomly zooms an image based on the defined zoom range.

Here is an example code to use the RandomZoom layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.transformation import RandomZoom
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(RandomZoom(start=0, end=1, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, start=0.0, end=1.0, probability=1.0, number_of_outputs=1, name=None) special

Init method for the RandomZoom layer.

Parameters:

Name Type Description Default
start float

Starting range of the zoom, the value should be between 0 and 1. Defaults to 0.

0.0
end float

Ending range of the zoom, the value should be between 0 and 1. Defaults to 1.

1.0
probability float

Probability rate for the layer, if the rate of 0.5 then the layer is applied on 50% of the images. Defaults to 1.0.

1.0
number_of_outputs int

Number of images to output. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the start parameter is not valid

ValueError

If the end parameter is not valid

ValueError

If the number_of_images parameter is not valid

ValueError

If the probability parameter is not valid

Source code in hocrox/layer/augmentation/transformation/random_zoom.py
def __init__(self, start=0.0, end=1.0, probability=1.0, number_of_outputs=1, name=None):
    """Init method for the RandomZoom layer.

    Args:
        start (float, optional): Starting range of the zoom, the value should be between 0 and 1. Defaults to 0.
        end (float, optional): Ending range of the zoom, the value should be between 0 and 1. Defaults to 1.
        probability (float, optional): Probability rate for the layer, if the rate of 0.5 then the layer is applied
            on 50% of the images. Defaults to 1.0.
        number_of_outputs (int, optional): Number of images to output. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the start parameter is not valid
        ValueError: If the end parameter is not valid
        ValueError: If the number_of_images parameter is not valid
        ValueError: If the probability parameter is not valid
    """
    if not (isinstance(start, float) and start >= 0 and start < 1):
        raise ValueError(f"The value {start} for the argument start is not valid")

    if not (isinstance(end, float) and end > 0 and end <= 1):
        raise ValueError(f"The value {end} for the argument end is not valid")

    if not isinstance(probability, float) or probability < 0.0 or probability > 1.0:
        raise ValueError(f"The value {probability} for the argument probability is not valid")

    if not isinstance(number_of_outputs, int) or number_of_outputs < 1:
        raise ValueError(f"The value {number_of_outputs} for the argument number_of_outputs is not valid")

    super().__init__(
        name,
        "random_zoom",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Start: {start}, end:{end}, Probability: {probability}, Number of Outputs: {number_of_outputs}",
    )

    self.__number_of_outputs = number_of_outputs
    self.__start = start
    self.__end = end
    self.__probability = probability

preprocessing special

Image preprocessing is the process of formatting and tweaking images before they are used by some models.

blur special

Preprocessing layers that blur images using different low-pass filters.

average

AverageBlur layer for Hocrox.

AverageBlur (Layer)

AverageBlur layer blur (image smoothing) an image using a normalized box filter.

Here is an example code to use the AverageBlur layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.blur import AverageBlur
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(AverageBlur(kernel_size=(5,5)))

# Printing the summary of the model
print(model.summary())
__init__(self, kernel_size, name=None) special

Init method for AverageBlur layer.

Parameters:

Name Type Description Default
kernel_size tuple

Kernel size for the filter

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the kernel_size parameter is not valid

Source code in hocrox/layer/preprocessing/blur/average.py
def __init__(self, kernel_size, name=None):
    """Init method for AverageBlur layer.

    Args:
        kernel_size (tuple): Kernel size for the filter
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the kernel_size parameter is not valid
    """
    if not isinstance(kernel_size, tuple):
        raise ValueError(f"The value {kernel_size} for the argument kernel_size is not valid")

    self.__kernel_size = kernel_size

    super().__init__(
        name,
        "average_blur",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Kernel Size: {self.__kernel_size}",
    )

bilateral

BilateralBlur layer for Hocrox.

BilateralBlur (Layer)

BilateralBlur layer blur (image smoothing) an image using an bilateral filter.

Here is an example code to use the BilateralBlur layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.blur import BilateralBlur
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(BilateralBlur(d=9, sigma_color=75, sigma_space=75))

# Printing the summary of the model
print(model.summary())
__init__(self, d, sigma_color, sigma_space, name=None) special

Init method for BilateralBlur layer.

Parameters:

Name Type Description Default
d int

Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace.

required
sigma_color float

Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting in larger areas of semi-equal color.

required
sigma_space float

Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is proportional to sigmaSpace.

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the d parameter is not valid

ValueError

If the sigma_color parameter is not valid

ValueError

If the sigma_space parameter is not valid

Source code in hocrox/layer/preprocessing/blur/bilateral.py
def __init__(self, d, sigma_color, sigma_space, name=None):
    """Init method for BilateralBlur layer.

    Args:
        d (int): Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
            it is computed from sigmaSpace.
        sigma_color (float): Filter sigma in the color space. A larger value of the parameter means that farther
            colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting in larger
            areas of semi-equal color.
        sigma_space (float): Filter sigma in the coordinate space. A larger value of the parameter means that
            farther pixels will influence each other as long as their colors are close enough (see sigmaColor ).
            When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is proportional
            to sigmaSpace.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the d parameter is not valid
        ValueError: If the sigma_color parameter is not valid
        ValueError: If the sigma_space parameter is not valid
    """
    if not isinstance(d, int):
        raise ValueError(f"The value {d} for the argument d is not valid")

    if not (sigma_color, float):
        raise ValueError(f"The value {sigma_color} for the argument sigma_color is not valid")

    if not (sigma_space, float):
        raise ValueError(f"The value {sigma_space} for the argument sigma_space is not valid")

    self.__d = d
    self.__sigma_space = sigma_space
    self.__sigma_color = sigma_color

    super().__init__(
        name,
        "bilateral_blur",
        self.STANDARD_SUPPORTED_LAYERS,
        f"D: {self.__d}, Sigma Space: {self.__sigma_space}, Sigma Color: {self.__sigma_color}",
    )

gaussian

GaussianBlur layer for Hocrox.

GaussianBlur (Layer)

GaussianBlur layer blur (image smoothing) an image using a gaussian filter.

Here is an example code to use the GaussianBlur layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.blur import GaussianBlur
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(GaussianBlur(kernel_size=(5,5), sigma_x=0, sigma_y=0)))

# Printing the summary of the model
print(model.summary())
__init__(self, kernel_size, sigma_x, sigma_y=0, name=None) special

Init method for GaussianBlur layer.

Parameters:

Name Type Description Default
kernel_size tuple

Kernel size for the filter

required
sigma_x float

Gaussian kernel standard deviation in X direction.

required
sigma_y float

Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from kernel_size.width and kernel_size.height, respectively.

0
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the kernel_size parameter is not valid

ValueError

If the sigma_x parameter is not valid

ValueError

If the sigma_y parameter is not valid

Source code in hocrox/layer/preprocessing/blur/gaussian.py
def __init__(self, kernel_size, sigma_x, sigma_y=0, name=None):
    """Init method for GaussianBlur layer.

    Args:
        kernel_size (tuple): Kernel size for the filter
        sigma_x (float): Gaussian kernel standard deviation in X direction.
        sigma_y (float, optional): Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set
            to be equal to sigmaX, if both sigmas are zeros, they are computed from
            kernel_size.width and kernel_size.height, respectively.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the kernel_size parameter is not valid
        ValueError: If the sigma_x parameter is not valid
        ValueError: If the sigma_y parameter is not valid
    """
    if not isinstance(kernel_size, tuple):
        raise ValueError(f"The value {kernel_size} for the argument kernel_size is not valid")

    if not (sigma_x, float):
        raise ValueError(f"The value {sigma_x} for the argument sigma_x is not valid")

    if not (sigma_y, float):
        raise ValueError(f"The value {sigma_y} for the argument sigma_y is not valid")

    self.__kernel_size = kernel_size
    self.__sigma_x = sigma_x
    self.__sigma_y = sigma_y

    super().__init__(
        name,
        "gaussian_blur",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Kernel Size: {self.__kernel_size}, Sigma X: {self.__sigma_x}, Sigma Y: {self.__sigma_y}",
    )

median

MedianBlur layer for Hocrox.

MedianBlur (Layer)

MedianBlur layer blur (image smoothing) an image using median filter.

Here is an example code to use the MedianBlur layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.blur import MedianBlur
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(MedianBlur(kernel_size=5))

# Printing the summary of the model
print(model.summary())
__init__(self, kernel_size, name=None) special

Init method for MedianBlur layer.

Parameters:

Name Type Description Default
kernel_size int

Aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7.

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the kernel_size parameter is not valid

Source code in hocrox/layer/preprocessing/blur/median.py
def __init__(self, kernel_size, name=None):
    """Init method for MedianBlur layer.

    Args:
        kernel_size (int): Aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the kernel_size parameter is not valid
    """
    if not isinstance(kernel_size, int) or kernel_size <= 0 or kernel_size % 2 == 0:
        raise ValueError(f"The value {kernel_size} for the argument kernel_size is not valid")

    self.__kernel_size = kernel_size
    super().__init__(
        name,
        "median_blur",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Kernel Size: {self.__kernel_size}",
    )

color special

Preprocessing layers that manapulats color of images.

brightness

Brightness layer for Hocrox.

Brightness (Layer)

RandomBrightness layer changes the brightness of the image based on the provided level.

Here is an example code to use the Brightness layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.color import Brightness
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Brightness(level=0.5))

# Printing the summary of the model
print(model.summary())
__init__(self, level=0.5, name=None) special

Init method for the Brightness layer.

Parameters:

Name Type Description Default
level float

Value of the brightness level. Defaults to 0.5.

0.5
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the level parameter is not valid

Source code in hocrox/layer/preprocessing/color/brightness.py
def __init__(self, level=0.5, name=None):
    """Init method for the Brightness layer.

    Args:
        level (float, optional): Value of the brightness level. Defaults to 0.5.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the level parameter is not valid
    """
    if not (isinstance(level, float)):
        raise ValueError(f"The value {level} for the argument level is not valid")

    super().__init__(
        name,
        "brightness",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Level: {level}",
    )

    self.__level = level

channel_shift

ChannelShift layer for Hocrox.

ChannelShift (Layer)

ChannelShift layer adds a value to the channels in the image.

Here is an example code to use the ChannelShift layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.color import ChannelShift
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(ChannelShift(value=1))

# Printing the summary of the model
print(model.summary())
__init__(self, value=1, name=None) special

Init method for the ChannelShift layer.

Parameters:

Name Type Description Default
value int

The value by which the channel will be shifted. Defaults to 1.

1
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the value parameter is not valid

Source code in hocrox/layer/preprocessing/color/channel_shift.py
def __init__(self, value=1, name=None):
    """Init method for the ChannelShift layer.

    Args:
        value (int, optional): The value by which the channel will be shifted. Defaults to 1.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the value parameter is not valid
    """
    if not (isinstance(value, int)):
        raise ValueError(f"The value {value} for the argument value is not valid")

    super().__init__(
        name,
        "channel_shift",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Value: {value}",
    )

    self.__value = value

grayscale

Grayscale layer for Hocrox.

Grayscale (Layer)

Grayscale layer grayscaled an image.

Here is an example code to use the Crop layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.color import Grayscale
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Grayscale())

# Printing the summary of the model
print(model.summary())
__init__(self, name=None) special

Init method for grayscale layer.

Parameters:

Name Type Description Default
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None
Source code in hocrox/layer/preprocessing/color/grayscale.py
def __init__(self, name=None):
    """Init method for grayscale layer.

    Args:
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    """
    super().__init__(
        name,
        "greyscale",
        self.STANDARD_SUPPORTED_LAYERS,
        "-",
    )

rescale

Rescale layer for Hocrox.

Rescale (Layer)

Rescale layer rescales an image.

Here is an example code to use the Rescale layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.color import Rescale
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Rescale(rescale=1.0 / 255.0))

# Printing the summary of the model
print(model.summary())
__init__(self, rescale=0.00392156862745098, name=None) special

Init method for Resize layer.

Parameters:

Name Type Description Default
rescale float

Rescale factor for rescaling image, Defaults to 1.0 / 255.0.

0.00392156862745098
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the rescale parameter is not valid

Source code in hocrox/layer/preprocessing/color/rescale.py
def __init__(self, rescale=1.0 / 255.0, name=None):
    """Init method for Resize layer.

    Args:
        rescale (float, optional): Rescale factor for rescaling image, Defaults to 1.0 / 255.0.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the rescale parameter is not valid
    """
    if not isinstance(rescale, float):
        raise ValueError(f"The value {rescale} for the argument rescale is not valid")

    self.__rescale = rescale

    super().__init__(
        name,
        "rescale",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Rescale: {self.__rescale}",
    )

flip special

Preprocessing layers that flips images.

horizontal_flip

HorizontalFlip layer for Hocrox.

HorizontalFlip (Layer)

HorizontalFlip layer horizontally flips an image.

Here is an example code to use the Crop layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.flip import HorizontalFlip
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(HorizontalFlip())

# Printing the summary of the model
print(model.summary())
__init__(self, name=None) special

Init method for horizontal flip layer.

Parameters:

Name Type Description Default
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None
Source code in hocrox/layer/preprocessing/flip/horizontal_flip.py
def __init__(self, name=None):
    """Init method for horizontal flip layer.

    Args:
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    """
    super().__init__(
        name,
        "horizontal_flip",
        self.STANDARD_SUPPORTED_LAYERS,
        "-",
    )

vertical_flip

VerticalFlip layer for Hocrox.

VerticalFlip (Layer)

VerticalFlip layer vertically flips an image.

Here is an example code to use the Crop layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.flip import VerticalFlip
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(VerticalFlip())

# Printing the summary of the model
print(model.summary())
__init__(self, name=None) special

Init method for horizontal flip layer.

Parameters:

Name Type Description Default
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None
Source code in hocrox/layer/preprocessing/flip/vertical_flip.py
def __init__(self, name=None):
    """Init method for horizontal flip layer.

    Args:
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    """
    super().__init__(
        name,
        "vertical_flip",
        self.STANDARD_SUPPORTED_LAYERS,
        "-",
    )

shift special

Preprocessing layers that shits images vertically or horizontally.

horizontal_shift

HorizontalShift layer for Hocrox.

HorizontalShift (Layer)

HorizontalShift layer shifts the image horizontally.

Here is an example code to use the HorizontalShift layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.shift import HorizontalShift
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(HorizontalShift(by=0.7, number_of_outputs=1))

# Printing the summary of the model
print(model.summary())
__init__(self, by=0.7, name=None) special

Init method for the HorizontalShift layer.

Parameters:

Name Type Description Default
by float

Rate of the shift, 0.0 means no change. Defaults to 0.7.

0.7
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the by parameter is not valid

Source code in hocrox/layer/preprocessing/shift/horizontal_shift.py
def __init__(self, by=0.7, name=None):
    """Init method for the HorizontalShift layer.

    Args:
        by (float, optional): Rate of the shift, 0.0 means no change. Defaults to 0.7.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the by parameter is not valid
    """
    if not (isinstance(by, float)):
        raise ValueError(f"The value {by} for the argument by is not valid")

    super().__init__(
        name,
        "horizontal_shift",
        self.STANDARD_SUPPORTED_LAYERS,
        f"By:{by}",
    )

    self.__by = by

vertical_shift

VerticalShift layer for Hocrox.

VerticalShift (Layer)

VerticalShift layer shifts the image vertically.

Here is an example code to use the VerticalShift layer in a model.

from hocrox.model import Model
from hocrox.layer.augmentation.shift import VerticalShift
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(VerticalShift(by=0.7))

# Printing the summary of the model
print(model.summary())
__init__(self, by=0.7, name=None) special

Init method for the VerticalShift layer.

Parameters:

Name Type Description Default
by float

Rate of the shift, 0.0 means no change. Defaults to 0.7.

0.7
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the by parameter is not valid

Source code in hocrox/layer/preprocessing/shift/vertical_shift.py
def __init__(self, by=0.7, name=None):
    """Init method for the VerticalShift layer.

    Args:
        by (float, optional): Rate of the shift, 0.0 means no change. Defaults to 0.7.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the by parameter is not valid
    """
    if not (isinstance(by, float)):
        raise ValueError(f"The value {by} for the argument by is not valid")

    super().__init__(
        name,
        "vertical_shift",
        self.STANDARD_SUPPORTED_LAYERS,
        f"By:{by}",
    )

    self.__by = by

transformation special

Preprocessing layers that transforms images.

convolution

Convolution layer for Hocrox.

Convolution (Layer)

Convolution layer convolves an image with the kernel.

Here is an example code to use the Convolution layer in a model.

import numpy as np

from hocrox.model import Model
from hocrox.layer.preprocessing.transformation import Convolution
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))

kernel = np.ones((5,5),np.float32)/25
model.add(Convolution(ddepth=-1, kernel=kernel))

# Printing the summary of the model
print(model.summary())
__init__(self, ddepth, kernel, name=None) special

Init method for the crop layer.

Parameters:

Name Type Description Default
ddepth int

Desired depth of the destination image.

required
kernel ndarray

Convolution kernel (or rather a correlation kernel), a single-channel floating point matrix; if you want to apply different kernels to different channels, split the image into separate color planes using split and process them individually.

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the parameter ddepth is not valid

ValueError

If the parameter kernel is not valid

Source code in hocrox/layer/preprocessing/transformation/convolution.py
def __init__(self, ddepth, kernel, name=None):
    """Init method for the crop layer.

    Args:
        ddepth (int): Desired depth of the destination image.
        kernel (ndarray): Convolution kernel (or rather a correlation kernel), a single-channel floating point
            matrix; if you want to apply different kernels to different channels, split the image into separate
            color planes using split and process them individually.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the parameter ddepth is not valid
        ValueError: If the parameter kernel is not valid
    """
    if not isinstance(ddepth, int):
        raise ValueError(f"The value {ddepth} for the argument ddepth is not valid")

    if not isinstance(kernel, np.ndarray):
        raise ValueError(f"The value {kernel} for the argument kernel is not valid")

    self.__ddepth = ddepth
    self.__kernel = kernel

    super().__init__(
        name,
        "crop",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Ddepth: {self.__ddepth}, Kernel: {self.__kernel}",
    )

crop

Crop layer for Hocrox.

Crop (Layer)

Crop layer crops an image.

Here is an example code to use the Crop layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.transformation import Crop
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Crop(x=10, y=10, w=100, h=100))

# Printing the summary of the model
print(model.summary())
__init__(self, x, y, w, h, name=None) special

Init method for the crop layer.

Parameters:

Name Type Description Default
x int

X coordinate for the crop.

required
y int

Y coordinate for the crop.

required
w int

Width of the cropped image.

required
h int

Height of the cropped image.

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the parameter x is not valid

ValueError

If the parameter y is not valid

ValueError

If the parameter w is not valid

ValueError

If the parameter h is not valid

Source code in hocrox/layer/preprocessing/transformation/crop.py
def __init__(self, x, y, w, h, name=None):
    """Init method for the crop layer.

    Args:
        x (int): X coordinate for the crop.
        y (int): Y coordinate for the crop.
        w (int): Width of the cropped image.
        h (int): Height of the cropped image.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the parameter x is not valid
        ValueError: If the parameter y is not valid
        ValueError: If the parameter w is not valid
        ValueError: If the parameter h is not valid
    """
    if x and not isinstance(x, int):
        raise ValueError(f"The value {x} for the argument x is not valid")

    if y and not isinstance(y, int):
        raise ValueError(f"The value {y} for the argument y is not valid")

    if w and not isinstance(w, int):
        raise ValueError(f"The value {w} for the argument w is not valid")

    if h and not isinstance(h, int):
        raise ValueError(f"The value {h} for the argument h is not valid")

    self.__x = x
    self.__y = y
    self.__w = w
    self.__h = h

    super().__init__(
        name,
        "crop",
        self.STANDARD_SUPPORTED_LAYERS,
        f"X: {self.__x}, Y: {self.__y}, W: {self.__w}, H: {self.__h}",
    )

pading

Padding layer for Hocrox.

Padding (Layer)

Padding layer adds padding to an image.

Here is an example code to use the Padding layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.transformation import Padding
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Padding(top=20, bottom=20, left=20, right=20, color=[255, 255, 255]))

# Printing the summary of the model
print(model.summary())
__init__(self, top, bottom, left, right, color=[255, 255, 255], name=None) special

Init method for Padding layer.

Parameters:

Name Type Description Default
top int

Top padding size.

required
bottom int

Bottom padding size.

required
left int

Left padding size.

required
right int

Right padding size.

required
color list

Color of the padding. Defaults to [255, 255, 255].

[255, 255, 255]
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the top parameter is not valid.

ValueError

If the bottom parameter is not valid.

ValueError

If the left parameter is not valid.

ValueError

If the right parameter is not valid.

ValueError

If the color parameter is not valid.

Source code in hocrox/layer/preprocessing/transformation/pading.py
def __init__(self, top, bottom, left, right, color=[255, 255, 255], name=None):
    """Init method for Padding layer.

    Args:
        top (int): Top padding size.
        bottom (int): Bottom padding size.
        left (int): Left padding size.
        right (int): Right padding size.
        color (list, optional): Color of the padding. Defaults to [255, 255, 255].
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the top parameter is not valid.
        ValueError: If the bottom parameter is not valid.
        ValueError: If the left parameter is not valid.
        ValueError: If the right parameter is not valid.
        ValueError: If the color parameter is not valid.
    """
    if top and not isinstance(top, int):
        raise ValueError(f"The value {top} for the argument top is not valid")

    if bottom and not isinstance(bottom, int):
        raise ValueError(f"The value {bottom} for the argument bottom is not valid")

    if left and not isinstance(left, int):
        raise ValueError(f"The value {left} for the argument left is not valid")

    if right and not isinstance(right, int):
        raise ValueError(f"The value {right} for the argument right is not valid")

    if not isinstance(color, list) or len(color) != 3:
        raise ValueError(f"The value {color} for the argument color is not valid")

    self.__top = top
    self.__bottom = bottom
    self.__right = right
    self.__left = left
    self.__color = color

    super().__init__(
        name,
        "padding",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Top: {self.__top}, Bottom: {self.__bottom}, Left: {self.__left}, Right: {self.__right}",
    )

resize

Resize layer for Hocrox.

Resize (Layer)

Resize layer resize an image to a specific dimension.

Here is an example code to use the Resize layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.transformation import Resize
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Resize(dim=(200,200), interpolation="INTER_LINEAR"))

# Printing the summary of the model
print(model.summary())
__init__(self, dim, interpolation='INTER_LINEAR', name=None) special

Init method for Resize layer.

Parameters:

Name Type Description Default
dim tuple

New dimension for the image

required
interpolation str

Interpolation method for the image. Defaults to "INTER_LINEAR".

'INTER_LINEAR'
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the dim parameter is not valid

ValueError

If the dim parameter values are less than 0

ValueError

If the interpolation parameter is not valid

Source code in hocrox/layer/preprocessing/transformation/resize.py
def __init__(self, dim, interpolation="INTER_LINEAR", name=None):
    """Init method for Resize layer.

    Args:
        dim (tuple): New dimension for the image
        interpolation (str, optional): Interpolation method for the image. Defaults to "INTER_LINEAR".
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the dim parameter is not valid
        ValueError: If the dim parameter values are less than 0
        ValueError: If the interpolation parameter is not valid
    """
    if not isinstance(dim, tuple):
        raise ValueError(f"The value {dim} for the argument dim is not valid")

    if dim[0] <= 0 or dim[1] <= 0:
        raise ValueError(f"The value {dim} for the argument dim is not valid")

    if interpolation not in ("INTER_LINEAR", "INTER_AREA", "INTER_CUBIC"):
        raise ValueError(f"The value {interpolation} for the argument interpolation is not valid")

    self.__dim = dim

    if interpolation == "INTER_LINEAR":
        self.__interpolation = cv2.INTER_LINEAR
    elif interpolation == "INTER_AREA":
        self.__interpolation = cv2.INTER_AREA
    else:
        self.__interpolation = cv2.INTER_CUBIC

    super().__init__(
        name,
        "resize",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Dim: {self.__dim}, Interpolation: {self.__interpolation}",
    )

rotate

Rotate layer for Hocrox.

Rotate (Layer)

Grayscale layer grayscaled an image.

Here is an example code to use the Crop layer in a model.

from hocrox.model import Model
from hocrox.layer.preprocessing.transformation import Grayscale
from hocrox.layer import Hocrox

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Grayscale())

# Printing the summary of the model
print(model.summary())
__init__(self, angle, name=None) special

Init method for the Rotate layer.

Parameters:

Name Type Description Default
angle float

Angle to ratate the image.

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the angle is not valid.

Source code in hocrox/layer/preprocessing/transformation/rotate.py
def __init__(self, angle, name=None):
    """Init method for the Rotate layer.

    Args:
        angle (float): Angle to ratate the image.
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the angle is not valid.
    """
    if not (isinstance(angle, int) or isinstance(angle, float)):
        raise ValueError(f"The value {angle} for the argument angle is not valid")

    self.__angle = angle

    super().__init__(
        name,
        "rotate",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Angle: {self.__angle}",
    )

read

Read layer for Hocrox.

Read (Layer)

Read layer reads images from the local filesystem.

Here is an example code to use the Read layer in a model.

from hocrox.model import Model
from hocrox.layer import Read

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))

# Printing the summary of the model
print(model.summary())

__init__(self, path, name=None) special

Init method for the Read layer.

Parameters:

Name Type Description Default
path str

Path to store the image

required
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the name parameter is invalid

Source code in hocrox/layer/read.py
def __init__(self, path, name=None):
    """Init method for the Read layer.

    Args:
        path (str): Path to store the image
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the name parameter is invalid
    """
    if path and not isinstance(path, str):
        raise ValueError(f"The value {path} for the argument path is not valid")

    self.__path = path

    super().__init__(
        name,
        "read",
        [],  # Read layer does not support any parent layers
        f"Path: {self.__path}",
    )

save

Save layer for Hocrox.

Save (Layer)

Save layer saves images on the local filesystem.

Here is an example code to use the Save layer in a model.

from hocrox.model import Model
from hocrox.layer import Read, Save

# Initializing the model
model = Model()

# Adding model layers
model.add(Read(path="./img"))
model.add(Save(path="./img_to_store", format="npy"))

# Printing the summary of the model
print(model.summary())

__init__(self, path, format='npy', name=None) special

Init method for the Save layer.

Parameters:

Name Type Description Default
path str

Path to store the image

required
format str

Format to save the image. Supported formats are npy and img. Defaults to "npy".

'npy'
name str

Name of the layer, if not provided then automatically generates a unique name for the layer. Defaults to None.

None

Exceptions:

Type Description
ValueError

If the name parameter is invalid

ValueError

If the format parameter is invalid

Source code in hocrox/layer/save.py
def __init__(self, path, format="npy", name=None):
    """Init method for the Save layer.

    Args:
        path (str): Path to store the image
        format (str, optional): Format to save the image. Supported formats are npy and img. Defaults to "npy".
        name (str, optional): Name of the layer, if not provided then automatically generates a unique name for
            the layer. Defaults to None.

    Raises:
        ValueError: If the name parameter is invalid
        ValueError: If the format parameter is invalid
    """
    if path and not isinstance(path, str):
        raise ValueError(f"The value {path} for the argument path is not valid")

    if format not in ("npy", "img"):
        raise ValueError(f"The value {format} for the argument format is not valid")

    self.__path = path
    self.__format = format

    super().__init__(
        name,
        "save",
        self.STANDARD_SUPPORTED_LAYERS,
        f"Path: {self.__path}, Format: {self.__format}",
    )