GTRefiner.GTRepresentation.PixelGTRepresentation package

Submodules

GTRefiner.GTRepresentation.PixelGTRepresentation.Layer module

class GTRefiner.GTRepresentation.PixelGTRepresentation.Layer.Layer(layer: Optional[ndarray] = None, img_dim: Optional[ImageDimension] = None, color=None)

Bases: object

The :class: Layer class is used to represent the different levels of the :class: PixelLevelGT class. It does not implement the :class: Scalable interface because Layer should only be instantiated once the resizing has been done. :param layer: binary array representing the layer :type layer: numpy.ndarayy :param img_dim: the size of the layer (static cannot be changed) :type img_dim: ImageDimension :param color: color of the layer :type color: tuple

classmethod bin_layer_from_rgb(img: Image) Layer

Returns a binary layer where every pixel equal to (0,0,0) is set to ‘0’, every other is set to ‘1’. :param img: Image to be turned into a binary layer where (0,0,0) is set to ‘0’, every other is set to ‘1’ :type img: Image :return: A layer corresponding to the binarized image where all black pixels (0,0,0) are set to 0 and the all the others are set to 1. :rtype: Layer

draw(page_elem: Drawable)
img_from_layer(rgb: bool = False) Image

Returns an Image, either binary or in RGB-mode, from the layer. :param rgb: If True this class returns an RGB Pillow Image, defaults to binary :return: Return a binary image from it’s mask by default

intersect(other: Layer) Layer

XOR of each pixel of two layers. Keeps the color of the current layer. :param other: Other Layer. :type other: Layer :return: A new Layer. :rtype: Layer

intersect_this_layer_with_an_rgb_img(img: Image) Image

Perform logical and of this layer with another image. For all pixels of this binary layer that are “True”, keep the RGB pixel of the Image given. :param img: Image to be masked with this layer, for all pixels of this binary layer that are “True”, keep the RGB pixel of the image given. :type img: Image :return: masked image. :rtype: Returns Image that has kept all its pixel wehre self.layer is “True” all others are set to (0,0,0) (black)

classmethod merge_and_draw(layers: List[Layer], img: Image = None) Image

Merges a list of layers onto a Pillow :class: Image Image while keeping their :param color: attribute. If only one layer is given, it will return it as a RGB Image. :param layers: The first layer in the list must be the base-layer. If only one layer is given. :type layers: List[Layer]The base-layer contains the base-object, the object that should be represented on the final Image. :param img: When given, it will draw the merged layers on this image. :type img: Image :return Image: return a Pillow :class: Image Image with moder RGB

paint_layer_on_img(img: Image, color=None) Image

Takes a base_img of mode RGB and overlays it with the layer of the current instance. Pixels corresponding to 0 are set to black (0,0,0). Pixels corresponding to 1 are kept. :param img: Image to be masked. :return: Masked Image with (0,0,0) where layer is 0.

paint_layer_on_img_and_keep_colors(img: Image, color: Tuple = None)

Overlay img with colored layer. The values > 0 from self.layer will overwrite the img, the rest of the pixels are kept as are. Make sure that the layer has a color. Color of the layer can be set with set_color() or the color param. :param img: img for the layer to be painted on. :type img: Image :param color: color in which the layer should be painted on the Image :type color: Image :return: :rtype:

set_color(color: Tuple)

Set color of the layer. :param color: Set color of the layer. :type color: tuple

set_visible(is_visible: bool)

Set visibility of the layer. :param is_visible: Set visibility of the layer. :type is_visible: bool

show()

Display the image

unite(other: Layer) Layer

Logical OR of each pixel of two layers. Keeps the color of the current layer. :param other: Other Layer. :type other: Layer :return: A new Layer. :rtype: Layer

GTRefiner.GTRepresentation.PixelGTRepresentation.PixelGT module

class GTRefiner.GTRepresentation.PixelGTRepresentation.PixelGT.MyImage(img: <module 'PIL.Image' from '/opt/miniconda3/envs/BachelorThesis/lib/python3.8/site-packages/PIL/Image.py'>)

Bases: GroundTruth

Wraper class for the pillow image and functionalities to manipulate it. :param img: ground truth image :type img: Image

binarize(img: <module 'PIL.Image' from '/opt/miniconda3/envs/BachelorThesis/lib/python3.8/site-packages/PIL/Image.py'> = None, bin_algo: str = 'otsu', **kwargs) array

Binarize the given image to based on either otsu, sauvola or niblack. :param img: img to be binarized :type img: Image to binarize, defaults to self.img :param bin_algo: either otsu, sauvola or niblack. Otsu binarizes base on a global threshhold, sauvola and niblack on a local threshold (based on a window size). :type bin_algo: str :param kwargs: if other than default parameters of sauvola or niblack should be used (see scikit documentation) :type kwargs: Any :return: returns a numpy array :rtype: ndarray

crop(current_dim: ImageDimension, target_dim: ImageDimension, cut_left: bool)

Crops the image of this instance to a target dimension. Cuts the off the black part on either the right or left side. Designed to be used before resizing ground truth. Suggested dimension is ImageDimension(4500, 6000). :param current_dim: Not used in this method :type current_dim: ImageDimension :param target_dim: Target dimension the cropped image should have :type target_dim: ImageDimension :param cut_left: Whether or not the left or right part of the image should be cut off. :type cut_left: bool

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Bicubic scaling of the ground-truth image based on a current dimension and a target dimension. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

show()

Show the image of the raw img (debugging purposes).

class GTRefiner.GTRepresentation.PixelGTRepresentation.PixelGT.PixelLevelGT(img: <module 'PIL.Image' from '/opt/miniconda3/envs/BachelorThesis/lib/python3.8/site-packages/PIL/Image.py'> = None, img_dim: ~GTRefiner.GTRepresentation.ImageDimension.ImageDimension = None)

Bases: MyImage

crop(current_dim: ImageDimension, target_dim: ImageDimension, cut_left: bool)

Crops the image of this instance to a target dimension. Cuts the off the black part on either the right or left side. Designed to be used before resizing ground truth. Suggested dimension is ImageDimension(4500, 6000). :param current_dim: Not used in this method :type current_dim: ImageDimension :param target_dim: Target dimension the cropped image should have :type target_dim: ImageDimension :param cut_left: Whether or not the left or right part of the image should be cut off. :type cut_left: bool

get_layer(layout_class: LayoutClasses) Layer

Returns the layer with the given layout_class.

merged_levels(visibility_table: Optional[VisibilityTable] = None, all_vis: bool = False) Layer

Only using this method will the client get the right pixel-gt. :param visibility_table: If a only certain layers are of interest they can be modified with a custom visibility table. :type visibility_table: VisibilityTable :param all_vis: given this parameter, it merges all layers. :type all_vis: bool :return: returns a binary layer :rtype: Layer

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the pixel ground-truths image and all levels (layers) of the instance in four steps. First, it blurs the binary image. Then it uses the bicubic scaling algorithm of Pillow (provided by the super-class RawImage), followed by binarizing it. Same procedure is applied to every layer. Is supposed to be applied exactly once. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

set_color(color_table: ColorTable)

Setter-method for the color.

set_visible(vis_table: VisibilityTable)

Setter-method for the is_visible field.

show()

Sho all the merged layers of the pixel_gt.

class GTRefiner.GTRepresentation.PixelGTRepresentation.PixelGT.RawImage(img: <module 'PIL.Image' from '/opt/miniconda3/envs/BachelorThesis/lib/python3.8/site-packages/PIL/Image.py'>)

Bases: MyImage

Raw image of the dataset.

get_cut_side() bool

Returns the orientation of the Page. If the page is left-oriented return true, if it’s right-oriented return false. :return: bool

Module contents