image_transformer.image_processors package

Submodules

image_transformer.image_processors.generic_grid_image_processor module

This module defines the GenericGridImageProcessor abstract base class, which provides an interface for processing grid-based images. Implementations of this class should provide methods to convert between pixel and grid coordinates, and to draw grid elements on a given context.

class image_transformer.image_processors.generic_grid_image_processor.GenericGridImageProcessor[source]

Bases: ABC

Abstract base class for processing grid-based images. This class defines the interface for converting between pixel and grid coordinates, and for drawing grid elements.

abstract approximate_number_of_grid_elements(width: int, height: int) int[source]

Abstract method to approximate the number of grid elements in an image.

Parameters:
  • width (int) – The width of the image.

  • height (int) – The height of the image.

Returns:

The approximated number of grid elements.

Return type:

int

abstract draw_grid_element_at(context: GenericOutputBuilder, grid_element_position: Tuple[int, ...], color: Tuple[int, int, int]) None[source]

Draw a grid element at the specified grid coordinates.

Parameters:
  • context (GenericOutputBuilder) – The drawing context.

  • grid_element_position (Tuple[int, ...]) – The position of the grid element in grid coordinates.

  • color (Tuple[int, int, int]) – The color to use for drawing the grid element, as an RGB tuple.

Returns:

None

abstract from_grid_coordinates_to_center_in_pixel_coordinates(grid_element_position: Tuple[int, ...]) Tuple[int, ...][source]

Convert grid coordinates to the center pixel coordinates of the grid element.

Parameters:

grid_element_position (Tuple[int, ...]) – The position of the grid element in grid coordinates.

Returns:

The center pixel coordinates of the grid element.

Return type:

Tuple[int, …]

abstract from_pixel_coordinates_to_grid_coordinates(x: int, y: int) Tuple[int, ...][source]

Convert pixel coordinates to grid coordinates.

Parameters:
  • x (int) – The x-coordinate in pixels.

  • y (int) – The y-coordinate in pixels.

Returns:

The corresponding grid coordinates.

Return type:

Tuple[int, …]

image_transformer.image_processors.hexagonal_grid_image_processor module

This module provides functionality to process images using a hexagonal grid layout. It includes methods to convert between pixel and grid coordinates, draw grid elements, and calculate hexagon vertices.

class image_transformer.image_processors.hexagonal_grid_image_processor.HexagonalGridImageProcessor(hexagon_size: int)[source]

Bases: GenericGridImageProcessor

A class to process images using a hexagonal grid layout.

approximate_number_of_grid_elements(width: int, height: int) int[source]

Approximates the number of hexagonal grid elements that can fit in the given width and height.

Parameters:
  • width (int) – The width of the area in pixels.

  • height (int) – The height of the area in pixels.

Returns:

The approximate number of hexagonal grid elements.

Return type:

int

draw_grid_element_at(context: GenericOutputBuilder, grid_element_position: Tuple[int, int], color: Tuple[int, int, int]) None[source]

Draws a hexagonal grid element at the specified grid coordinates.

Parameters:
  • context (GenericOutputBuilder) – The Cairo context to draw on.

  • grid_element_position (Tuple[int, int]) – The grid coordinates (q, r).

  • color (Tuple[int, int, int]) – The color of the hexagon in RGB format.

from_grid_coordinates_to_center_in_pixel_coordinates(grid_element_position: Tuple[int, int]) Tuple[int, int][source]

Converts grid coordinates to the center pixel coordinates.

Parameters:

grid_element_position (Tuple[int, int]) – The grid coordinates (q, r).

Returns:

The corresponding center pixel coordinates (x, y).

Return type:

Tuple[int, int]

from_pixel_coordinates_to_grid_coordinates(x: int, y: int) Tuple[int, int][source]

Converts pixel coordinates to grid coordinates.

Parameters:
  • x (int) – The x-coordinate in pixels.

  • y (int) – The y-coordinate in pixels.

Returns:

The corresponding grid coordinates (q, r).

Return type:

Tuple[int, int]

image_transformer.image_processors.square_grid_image_processor module

This module contains the SquareGridImageProcessor class, which is used to process images by dividing them into a grid of squares.

class image_transformer.image_processors.square_grid_image_processor.SquareGridImageProcessor(square_size: int)[source]

Bases: GenericGridImageProcessor

A class to process images by dividing them into a grid of squares.

approximate_number_of_grid_elements(width: int, height: int) int[source]

Approximates the number of grid elements that can fit in the given width and height.

Parameters:
  • width (int) – The width of the area in pixels.

  • height (int) – The height of the area in pixels.

Returns:

The approximate number of grid elements.

Return type:

int

draw_grid_element_at(context: GenericOutputBuilder, grid_element_position: Tuple[int, int], color: Tuple[int, int, int]) None[source]

Draws a grid element at the specified position with the given color.

Parameters:
  • context (Context) – The Cairo context to draw on.

  • grid_element_position (Tuple[int, int]) – The position of the grid element as a tuple (grid_x, grid_y).

  • color (Tuple[int, int, int]) – The color of the grid element as a tuple (r, g, b).

from_grid_coordinates_to_center_in_pixel_coordinates(grid_element_position: Tuple[int, int]) Tuple[int, ...][source]

Converts grid coordinates to the center pixel coordinates of the grid element.

Parameters:

grid_element_position (Tuple[int, int]) – The position of the grid element as a tuple (grid_x, grid_y).

Returns:

The center pixel coordinates as a tuple (center_x, center_y).

Return type:

Tuple[int, …]

from_pixel_coordinates_to_grid_coordinates(x: int, y: int) Tuple[int, ...][source]

Converts pixel coordinates to grid coordinates.

Parameters:
  • x (int) – The x-coordinate in pixels.

  • y (int) – The y-coordinate in pixels.

Returns:

The grid coordinates as a tuple (grid_x, grid_y).

Return type:

Tuple[int, …]

image_transformer.image_processors.triangle_grid_image_processor module

This module provides functionality to process images using a hexagonal grid layout. It includes methods to convert between pixel and grid coordinates, draw grid elements, and calculate hexagon vertices.

class image_transformer.image_processors.triangle_grid_image_processor.TriangleGridImageProcessor(hexagon_size: int)[source]

Bases: GenericGridImageProcessor

A class to process images using a hexagonal grid layout.

approximate_number_of_grid_elements(width: int, height: int) int[source]

Approximates the number of hexagonal grid elements that can fit in the given width and height.

Parameters:
  • width (int) – The width of the area in pixels.

  • height (int) – The height of the area in pixels.

Returns:

The approximate number of hexagonal grid elements.

Return type:

int

draw_grid_element_at(context: GenericOutputBuilder, grid_element_position: Tuple[int, int], color: Tuple[int, int, int]) None[source]

Draws a hexagonal grid element at the specified grid coordinates.

Parameters:
  • context (GenericOutputBuilder) – The Cairo context to draw on.

  • grid_element_position (Tuple[int, int]) – The grid coordinates (q, r).

  • color (Tuple[int, int, int]) – The color of the hexagon in RGB format.

from_grid_coordinates_to_center_in_pixel_coordinates(grid_element_position: Tuple[int, int]) Tuple[int, int][source]

Converts grid coordinates to the center pixel coordinates.

Parameters:

grid_element_position (Tuple[int, int]) – The grid coordinates (q, r).

Returns:

The corresponding center pixel coordinates (x, y).

Return type:

Tuple[int, int]

from_pixel_coordinates_to_grid_coordinates(x: int, y: int) Tuple[int, int][source]

Converts pixel coordinates to grid coordinates.

Parameters:
  • x (int) – The x-coordinate in pixels.

  • y (int) – The y-coordinate in pixels.

Returns:

The corresponding grid coordinates (q, r).

Return type:

Tuple[int, int]

Module contents

This module initializes the image_processors package by importing all functions and classes from the image_processors module.