Utilities

pydetecdiv.utils

A set of general utility functions

pydetecdiv.utils.singleton(class_) Callable

Definition of a singleton annotation, creating an object if it does not exist yet or returning the current one if it exists

Parameters:

class – the singleton class

Returns:

the singleton instance

pydetecdiv.utils.round_to_even(value: float, ceil: bool = True) int

Round a float value to an even integer. If ceil is True then the returned integer is the first even number equal to or larger than the rounded integer, otherwise, it is the first smaller or equal even number

Parameters:
  • value (float) – the value to round to an even number

  • ceil (bool) – True if the even value should be greater than or equal to the rounded value

Returns:

the rounded value

Return type:

int

pydetecdiv.utils.remove_keys_from_dict(dictionary: dict[str | Any, Any], keys: list[str | Any])

Remove the dictionary entries whose keys are in the key list

Parameters:
  • dictionary (dict) – the dictionary to remove items from

  • keys (list of str or any object that can be used a dictionary key) – the key list

Returns:

the filtered dictionary

Return type:

dict

pydetecdiv.utils.increment_string(s: str) str

Increments a string by one: a becomes b, which in turn becomes c, etc. After z comes aa, and so on.

Parameters:

s – the string to increment

Returns:

the incremented string

pydetecdiv.utils.path

A utility module for path manipulation

pydetecdiv.utils.path.stem(path: str) str

Return the basename of a file without extension

Parameters:

path (str) – the file path

Returns:

the file basename without extension

Return type:

str

pydetecdiv.utils.ImageResource

Utility classes to manipulate Image resources

class pydetecdiv.utils.ImageResource.Dimension(x: int, y: int, z: int = 1, c: int = 1, t: int = 1)

Bases: object

A utility class to handle Image resource dimension in ImageResourceDAO ORM objects

class pydetecdiv.utils.ImageResource.Shape(x: int, y: int)

Bases: object

A utility class to handle Image resource shape in ImageResourceDAO ORM objects

class pydetecdiv.utils.ImageResource.Image(z: int = 0, c: int = 0, t: int = 0)

Bases: object

A utility class to handle 2D Image in ImageResourceDAO ORM objects

pydetecdiv.utils.Shapes

A utility module defining classes of shapes

class pydetecdiv.utils.Shapes.Box(top_left: tuple[int, int] = None, bottom_right: tuple[int, int] = None)

Bases: object

A utility class defining a Box for use by all classes representing two-dimensional objects such as images.

property top_left: tuple[int, int]

top left corner of the box

Returns:

coordinates of the top left corner of the box

Return type:

tuple of two int

property bottom_right: tuple[int, int]

bottom right corner of the box

Returns:

coordinates of the bottom right corner of the box

Return type:

tuple of two int

property width: int

width of the box

Returns:

width of the box

Return type:

int

property height: int

height of the box

Returns:

height of the box

Return type:

int

property size: tuple[int, int]

size dimensions of the box, i.e. width and height

Returns:

size dimensions of the box

Return type:

tuple of two int

lies_in(other: Box) bool

Checks whether the current object lies within the boundaries of another box

Parameters:

other (Box) – the other box

Returns:

True if the current box is totally comprised in the other one

Return type:

bool