GTRefiner.GTRepresentation.VectorGTRepresentation package

Submodules

GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements module

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.AscenderDescenderRegion(text_line: TextLine, x_height: int)

Bases: TextLineDecoration

Decorator of Textline which adds an x-region, ascender- and descender-region. :param text_line: Textline to be decorated. :param top_line: Represents the top line of x_region. :type top_line: Line :param x_region: Denotes the region for little x. :type x_region: Quadrilateral :param ascender_region: Denotes the region of ascenders. :type ascender_region: Quadrilateral :param descender_region: Denotes the region of descenders. :type descender_region: Quadrilateral The rest of the parameters are used to give custom colors to each of the Polygon vectorobjects for debugging purposes the different fields have.

build() Dict

Helper function to build the json file.

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

Crop the page element to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: ImageDraw, color: Tuple = None, outline=None)

Draw the page element :class: PageElement polygon with the instance color if no other color is given. :param drawer: image to be drawn upon. :type drawer: ImageDraw.ImageDraw :param color: fill of the object. Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type color: tuple :param outline: outline of the object. Should only be used for illustration purposes! Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type outline: tuple

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

Returns a list of layers for every VectorObject of a PageElement according to the order defined chosen with the implementation. (We suggest, you change it to a dict of LayoutClasses and Layers for a safer implementation.) :param img: base img to be drawn upon. :type img: Image :param layers: layers of vector objects each drawn on a layer. This PageElement will be drawn on a new layer and added to the list. :type layers: List[Layer] :return: layers: layers of vectorobjects (including this instance) each drawn on a layer. :rtype:layers: List[Layer]

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the current :class: PageElement to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) should be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

set_color(color: Optional[Tuple] = None, color_table: Optional[ColorTable] = None)

Setter-method for the color. :param color: What color to use when drawn. :type color: Tuple

set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

show()

Displays the polygon of the PageElement for debugging purposes.

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.AscenderRegion(polygon: Polygon, top_line: TopLine, id: int = 0)

Bases: TextLineElements

Region to represent ascenders. It is built based on a top_line and the polygon of the text_line :param polygon: Textline polygon. :type polygon: Polygon :param top_line: Top line (base line - some y value representing the x-height) :type top_line: TopLine :param id: To identify the region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.BaseLine(base_line: Line, id: int = 0)

Bases: TextLineElements

set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.CommentTextLine(polygon: Polygon, base_line: BaseLine, color: Tuple = (255, 255, 255), is_visible: bool = True, id: int = 0)

Bases: TextLine

The :class: CommentTextLine class has no further characteristic than it’s name. It instantiates the abstract super class :class: PageElement. :param polygon: represents the contour of the text line. :type polygon: Polygon :param base_line: Every :class: TextLine class comes with a default base_line provided by the original xml_gt. :type base_line: Line :param color: color of the line, defaults to white :type color: tuple :param is_visible: set visible or invisible, defaults to true :type is_visible: bool :param id: To identify the text region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.DecorationElement(polygon: Polygon, id: int = 0)

Bases: PageElement

The :class: DecorationElement class has no further characteristic than it’s name. It instantiates the abstract super class :class: PageElement.

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.DescenderRegion(polygon: Polygon, base_line: BaseLine, id: int = 0)

Bases: TextLineElements

Region to represent descenders. It is built based on a base_line and the polygon of the text_line :param polygon: Text line polygon. :type polygon: Polygon :param top_line: Base line (base line - some y value representing the x-height) :type top_line: BaseLine :param id: To identify the region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.HeadAndTailRegion(text_line: TextLine)

Bases: TextLineDecoration

Example for another decoration. A line could be devided into a head part (with initial) and tail part.

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.MainTextLine(polygon: Polygon, base_line: BaseLine, color: Tuple = (255, 255, 255), is_visible: bool = True, id: int = 0)

Bases: TextLine

The :class: MainTextLine class has no further characteristic than it’s name. It instantiates the abstract super class :class: PageElement. :param polygon: represents the contour of the text line. :type polygon: Polygon :param base_line: Every :class: TextLine class comes with a default base_line provided by the original xml_gt. :type base_line: Line :param color: color of the line, defaults to white :type color: tuple :param is_visible: set visible or invisible, defaults to true :type is_visible: bool :param id: To identify the text region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.PageElement(polygon: Polygon, color: Optional[Tuple] = None, is_visible: bool = False, id: int = 0)

Bases: Scalable, Drawable, Showable, Croppable, Layarable, Dictionable

Super class for all page elements, such as decorations & textlines. Every PageElement holds a polygon :class: Polygon`at its core. If further characteristics shall be added, we suggest to use the decoration pattern. :param polygon: Represents the contour of the page element. :type polygon: Polygon :param color: What color to use when drawn. :type color: Tuple :param id: To identify the text_line. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int :param is_visible: Whether or not is should be recognized as visible to the :class: `Writer. :type is_visible: bool

build() Dict

Helper function to build the json file.

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

Crop the page element to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: ImageDraw, color: Tuple = None, outline: Tuple = None)

Draw the page element :class: PageElement polygon with the instance color if no other color is given. :param drawer: image to be drawn upon. :type drawer: ImageDraw.ImageDraw :param color: fill of the object. Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type color: tuple :param outline: outline of the object. Should only be used for illustration purposes! Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type outline: tuple

get_color()

Returns the page element’s color :return: the page element’s color :rtype: tuple

get_id()
get_min_y()

Getter method for the minimum y coordinate of this PageElement.

is_visible() bool

Getter-method for the is_visible field. :return: Whether or not is should be recognized as visible

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

Returns a list of layers for every VectorObject of a PageElement according to the order defined chosen with the implementation. (We suggest, you change it to a dict of LayoutClasses and Layers for a safer implementation.) :param img: base img to be drawn upon. :type img: Image :param layers: layers of vector objects each drawn on a layer. This PageElement will be drawn on a new layer and added to the list. :type layers: List[Layer] :return: layers: layers of vectorobjects (including this instance) each drawn on a layer. :rtype:layers: List[Layer]

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the current :class: PageElement to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) should be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

set_color(color: Optional[Tuple] = None, color_table: Optional[ColorTable] = None)

Setter-method for the color. :param color: What color to use when drawn. :type color: Tuple

set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

show()

Displays the polygon of the PageElement for debugging purposes.

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.TextLine(polygon: Polygon, base_line: BaseLine, color: Tuple = (255, 255, 255), is_visible: bool = True, id: int = 0)

Bases: PageElement

Represents all PageElements with text line characteristics. Examples are comment lines and main-text lines. :param polygon: represents the contour of the text line. :type polygon: Polygon :param base_line: Every :class: TextLine class comes with a default base_line provided by the original xml_gt. :type base_line: Line :param color: color of the line, defaults to white :type color: tuple :param is_visible: set visible or invisible, defaults to true :type is_visible: bool :param id: To identify the text region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

build() Dict

Helper function to build the json file.

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

Crop the page element to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: ImageDraw, color: Tuple = None, outline=None)

Draw the page element :class: PageElement polygon with the instance color if no other color is given. :param drawer: image to be drawn upon. :type drawer: ImageDraw.ImageDraw :param color: fill of the object. Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type color: tuple :param outline: outline of the object. Should only be used for illustration purposes! Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type outline: tuple

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

Returns a list of layers for every VectorObject of a PageElement according to the order defined chosen with the implementation. (We suggest, you change it to a dict of LayoutClasses and Layers for a safer implementation.) :param img: base img to be drawn upon. :type img: Image :param layers: layers of vector objects each drawn on a layer. This PageElement will be drawn on a new layer and added to the list. :type layers: List[Layer] :return: layers: layers of vectorobjects (including this instance) each drawn on a layer. :rtype:layers: List[Layer]

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the current :class: PageElement to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) should be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

set_color(color: Optional[Tuple] = None, color_table: Optional[ColorTable] = None)

Setter-method for the color. :param color: What color to use when drawn. :type color: Tuple

set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.TextLineDecoration(text_line: TextLine)

Bases: TextLine

Decorator class used to add further functionalities to :class: TextLine page elements. :param polygon: represents the contour of the text line. :type polygon: Polygon :param base_line: Every :class: TextLine class comes with a default base_line provided by the original xml_gt. :type base_line: Line :param color: color of the line, defaults to white :type color: tuple :param is_visible: set visible or invisible, defaults to true :type is_visible: bool :param id: To identify the text region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

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

Crop the page element to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

abstract draw(drawer: ImageDraw, color: Tuple = None, outline=None)

Draw the page element :class: PageElement polygon with the instance color if no other color is given. :param drawer: image to be drawn upon. :type drawer: ImageDraw.ImageDraw :param color: fill of the object. Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type color: tuple :param outline: outline of the object. Should only be used for illustration purposes! Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type outline: tuple

abstract resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the current :class: PageElement to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) should be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

abstract set_color(color: Optional[Tuple] = None, color_table: Optional[ColorTable] = None)

Setter-method for the color. :param color: What color to use when drawn. :type color: Tuple

abstract set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

abstract show()

Displays the polygon of the PageElement for debugging purposes.

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.TextLineElements(polygon: Polygon, id: int = 0)

Bases: PageElement

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.TextRegionElement(bounding_box: Rectangle, id: int = 0)

Bases: TextLineElements

Represents the bounding box of a Text-Region. Helps illustrate and the structure of the vector_gt. :param bounding_box: bounding box of the Text-Region. :type bounding_box: bounding box of the Text-Region. :param id: To identify the text region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

draw(drawer: ImageDraw, color: Tuple = None, outline: Tuple = None)

Draw the page element polygon with the instance color if no other coller is given. Fill it, if and only if the set_filled parameter is true.

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.TopLine(base_line: BaseLine, x_height: int, id: int = 0)

Bases: TextLineElements

set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageElements.XRegion(base_line: BaseLine, top_line: TopLine, id: int = 0)

Bases: TextLineElements

Region to represent x-Height (or XRegion as it’s called in this program) based on a top_line and the polygon of the text_line :param base_line: Base line (base line - some y value representing the x-height) :type base_line: BaseLine :param top_line: top_line: Top line (base line - some y value representing the x-height) :type top_line: TopLine :param id: To identify the region. Helpful for coloring, sorting, etc. Not mandatory, default value is 0. :type id: int

GTRefiner.GTRepresentation.VectorGTRepresentation.PageLayout module

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageLayout.Layout(page_elements: Optional[List[PageElement]] = None, layout_class: Optional[LayoutClasses] = None)

Bases: Scalable, Drawable, Croppable, Dictionable, Layarable

Parameters:
  • page_elements (List[PageElement]) – List of all page elements of a layout (e.g. comment text lines or decorations).

  • layout_class (LayoutClasses) – The class of the layout (e.g. COMMENT or DECORATION)

add_elem(elem: PageElement)

Append an element to this layout. Can also be done with the built-in function append, however this method is is safer. :param elem: :type elem: :return: :rtype:

build() Dict

Introduces the behaviour of a JSON compliant represenation. The returned dictionary is supposed to be stored in a JSON file. :return: Dictionary of all the vector objects of interest. :rtype: dict

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

Crop all page elements of this layout to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: ImageDraw, color: Optional[Tuple] = None, outline=None)

If layout is visible, draw all page elements of this layout on the given image in a certain color and outline. :param drawer: image to be drawn upon. :type drawer: ImageDraw.ImageDraw :param color: fill of the object. Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type color: tuple :param outline: outline of the object. Should only be used for illustration purposes! Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type outline: tuple

get_region_bbox() TextRegionElement

Dynamically returns a TextRegion element.

layer(img: Image)

Returns a image of all layers for every PageElement according to the order chosen with the implementation. (We suggest, you change it to a dict of LayoutClasses and Layers for a safer implementation.) :param img: base img to be drawn upon. :type img: Image TODO: Make safer with dict.

merge(other: Layout)

Merge this layout with another one. Doesn’t do any layout_class checks. Client must be sure that they are both of the same layout class.

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes all page elements :class: List[PageElement] of the current :class: LayoutClass to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) must be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

set_color(color: Optional[Tuple] = None, color_table: Optional[ColorTable] = None)

Setter-method for the color. :param color: What color to use when drawn. :type color: Tuple

set_visible(is_visible: Optional[bool] = None, vis_table: Optional[VisibilityTable] = None)

Setter-method for the is_visible field. :param is_visible: Whether or not is should be recognized as visible :type is_visible: bool

class GTRefiner.GTRepresentation.VectorGTRepresentation.PageLayout.TextRegion(layout: Optional[Layout] = None, text_regions: Optional[List[Layout]] = None)

Bases: Layout

add_region(layout: Layout)

Add a layout to the region. Doesn’t do any layout_class checks. Client must be sure that they are both of the same layout class. :param layout: Layout to be added to the region. :type layout: Layout

build() Dict

Introduces the behaviour of a JSON compliant represenation. The returned dictionary is supposed to be stored in a JSON file. :return: Dictionary of all the vector objects of interest. :rtype: dict

get_region_bbox() TextRegionElement

Dynamically returns a TextRegion element.

layer(img: Image)

Returns a image of all layers for every layout on the corresponding layer according to the order chosen with the implementation. :param img: base img to be drawn upon. :type img: Image

sort_layout_elements(reverse: bool = False)

Sorts the page_elements of a text_region by the min y value of the page elements.

GTRefiner.GTRepresentation.VectorGTRepresentation.VectorGT module

class GTRefiner.GTRepresentation.VectorGTRepresentation.VectorGT.VectorGT(regions: List[TextRegion], img_dim: ImageDimension)

Bases: GroundTruth, Dictionable, Scalable, Croppable, Drawable

build() Dict

Introduces the behaviour of a JSON compliant represenation. The returned dictionary is supposed to be stored in a JSON file. :return: Dictionary of all the vector objects of interest. :rtype: dict

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

Crop all page elements of this vector gt to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: <module 'PIL.ImageDraw' from '/opt/miniconda3/envs/BachelorThesis/lib/python3.8/site-packages/PIL/ImageDraw.py'>, color: ~typing.Optional[~typing.Tuple] = None, outline=None)

For all visible layouts and pagelements, draw them on given image in a certain color and outline. TODO: What’s the difference of this method to the layer method? :param drawer: image to be drawn upon. :type drawer: ImageDraw.ImageDraw :param color: fill of the object. Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type color: tuple :param outline: outline of the object. Should only be used for illustration purposes! Can be of any mode that pillow understands (e.g. RGBA, 1, L, RGB). :type outline: tuple

get_dim()
Returns:

Return the dimension of this vector_gt

Return type:

ImageDimension

layer(img)

Draw all visible page_elements of all visible layers of all visible regions on an image.

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes all page elements :class: List[PageElement] of the current :class: LayoutClass to a given target dimension. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

show(base_img: <module 'PIL.Image' from '/opt/miniconda3/envs/BachelorThesis/lib/python3.8/site-packages/PIL/Image.py'> = None, transparency=0.5, color: ~typing.Tuple = None, outline: ~typing.Tuple = None)

Illustrate the vector ground truth according to the clients needs (especially useful for debugging). :param base_img: If given, this image will be the base image where the vector objects are drawn upon. :type base_img: Image :param transparency: The factor to which the layers should be overlayed. A value smaller than 0.5 prioritizes the base img. A value bigger than 05. prioritizes the vector objects. :type transparency: int :param color: color the page elements should be drawn in. We suggest you use a color table and :class: Colorer to color the elements individually. :type color: tuple :param outline: Outline of the vector objects to be drawn (illustrated). :type outline: tuple :return: :rtype:

GTRefiner.GTRepresentation.VectorGTRepresentation.VectorObjects module

class GTRefiner.GTRepresentation.VectorGTRepresentation.VectorObjects.Line(xy)

Bases: Polygon

Represents a line of two coordinates.

draw(drawer: ImageDraw, outline=None, color: Tuple = None)

Draw the vector object on a given object. :param drawer: Pillow drawer, can be of any mode (example “1”, “RGB”, “RGBA”). The color parameter must be corresponding format. :type drawer: ImageDraw.ImageDraw :param color: Single element tuple for binary, triple tuple for RGB, quadruple tuple for RGBA (consult PILLOW Documenation for more information). :type color: tuple :param outline: Only use this parameter for illustration purposes. Using it for ground truth generation is dangerous. :type outline: tuple :return: :rtype:

get_max_x_coord()
get_min_x_coord()
class GTRefiner.GTRepresentation.VectorGTRepresentation.VectorObjects.Polygon(xy: List[Tuple])

Bases: Scalable, Drawable, Croppable, Dictionable

This class is the parent class of all vector objects used to represent the vector ground truth. :param xy: is a polygon of 2 or more coordinates. :type xy: represents the coordinates [(x1,x1),(x2,y2),…] of the polygon. It’s important the polygon is sorted. No checks are made for that. It doesn’t matter if the polygon is closed or open (the last coordinate doesn’t need to be the first coordinate).

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

Crop this vector object to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: ImageDraw, color: Tuple = None, outline: Tuple = None)

Draw the vector object on a given object. :param drawer: Pillow drawer, can be of any mode (example “1”, “RGB”, “RGBA”). The color parameter must be corresponding format. :type drawer: ImageDraw.ImageDraw :param color: Single element tuple for binary, triple tuple for RGB, quadruple tuple for RGBA (consult PILLOW Documenation for more information). :type color: tuple :param outline: Only use this parameter for illustration purposes. Using it for ground truth generation is dangerous. :type outline: tuple :return: :rtype:

get_bbox() Rectangle

Get bounding box of the vector object. :return: returns a rectangle defining the bounding box. :rtype: Rectangle

get_max_x()

Get max x coordinate of all the coordinates of this vector object. :return: max x :rtype: int

get_max_y()

Get max y coordinate of all the coordinates of this vector object. :return: max y :rtype: int

get_min_x()

Get min x coordinate of all the coordinates of this vector object. :return: min x :rtype: int

get_min_y()

Get min y coordinate of all the coordinates of this vector object. :return: min y :rtype: int

resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the vector object to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) must be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

class GTRefiner.GTRepresentation.VectorGTRepresentation.VectorObjects.Quadrilateral(xy: List[Tuple])

Bases: Polygon

Parameters:

xy – 4 coords that represent a quadrilateral. which are sorted upon initialisation to ensure a useful representation with the draw method.

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

Crop this vector object to a target dimension. Due to the nature of the ground truth document :param cut_left: must be provided. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension :param cut_left: Whether or not the page is cut_left or not. :type cut_left: bool

draw(drawer: ImageDraw, color=None, outline=None)

Draw the vector object on a given object. :param drawer: Pillow drawer, can be of any mode (example “1”, “RGB”, “RGBA”). The color parameter must be corresponding format. :type drawer: ImageDraw.ImageDraw :param color: Single element tuple for binary, triple tuple for RGB, quadruple tuple for RGBA (consult PILLOW Documenation for more information). :type color: tuple :param outline: Only use this parameter for illustration purposes. Using it for ground truth generation is dangerous. :type outline: tuple :return: :rtype:

is_sorted()
resize(current_dim: ImageDimension, target_dim: ImageDimension)

Resizes the vector object to a given target dimension. As this class doesn’t possess a image dimension parameter, both the current dimension (of the page) and the target dimension (the size to be scaled to) must be given. :param current_dim: Current dimension :type current_dim: ImageDimension :param target_dim: Target dimension :type target_dim: ImageDimension

class GTRefiner.GTRepresentation.VectorGTRepresentation.VectorObjects.Rectangle(xy)

Bases: Polygon

Represents a rectangle :param xy: 4 coords that represent a quadrilateral. which are sorted upon initialisation to ensure a useful representation with the draw method. :type tuple

draw(drawer: ImageDraw, color: Tuple = None, outline=None, width=None)

Draw the vector object on a given object. :param drawer: Pillow drawer, can be of any mode (example “1”, “RGB”, “RGBA”). The color parameter must be corresponding format. :type drawer: ImageDraw.ImageDraw :param color: Single element tuple for binary, triple tuple for RGB, quadruple tuple for RGBA (consult PILLOW Documenation for more information). :type color: tuple :param outline: Only use this parameter for illustration purposes. Using it for ground truth generation is dangerous. :type outline: tuple :return: :rtype:

Module contents