unified_image_reader package

Subpackages

Submodules

unified_image_reader.config module

unified_image_reader.image module

An interface into optimized image reading behavior with optional overriding.

class unified_image_reader.image.Image(filepath, reader=None)

Bases: contextlib.AbstractContextManager

Image An image to be streamed into a specialized reader

property dims

dims Get the width and height properties of the image

Returns

Width and height in pixels

Return type

Tuple[int]

get_region(region_identifier, region_dims=(512, 512)) numpy.ndarray

get_region Get a pixel region from the image

Parameters
  • region_identifier (Union[int, Iterable]) – A set of (width, height) coordinates or an indexed region based on region dimensions

  • region_dims (Iterable, optional) – A set of (width, height) coordinates representing the region dimensions, defaults to DEFAULT_REGION_DIMS

Returns

A numpy array representative of the pixel region from the image

Return type

np.ndarray

property height

height Get the height property of the image using its reader

Returns

Height in pixels

Return type

int

number_of_regions(region_dims=(512, 512)) int

number_of_regions Get total number of regions from the image based on region dimensions

Parameters

region_dims (Iterable, optional) – A set of (width, height) coordinates representing the region dimensions, defaults to DEFAULT_REGION_DIMS

Returns

Number of regions in the image

Return type

int

property width

width Get the width property of the image using its reader

Returns

Width in pixels

Return type

int

unified_image_reader.image_reader module

An ImageReader controls the behavior of the image interface. It can either utilize an adapter on a library or custom behavior.

class unified_image_reader.image_reader.ImageReader(filepath: str, adapter: Optional[unified_image_reader.adapters.adapter.Adapter] = None)

Bases: object

ImageReader Interface between images and adapters which specify reading behavior

Raises
  • UnsupportedFormatException – The adapter does not support the image format

  • TypeError – Enforces provided type hinting for region_identifier arguments

  • IndexError – The top-left pixel or pixel region dimensions are out of bounds of the image dimensions

  • InvalidCoordinatesException – The top-left pixel rwas not provided in (width, height) format

  • InvalidDimensionsException – Dimensions of the pixel region were not provided in (width, height) format

property dims

dims Get the width and height property of the image using the adapter’s implementation

Returns

Width and height in pixels

Return type

Iterable

get_region(region_identifier: Union[int, Iterable], region_dims: Iterable)

get_region Get a pixel region from an image using an adapter’s implementation after validation and extracting region data

Raises

TypeError – The starting pixels or pixel regions are out of bounds of the image dimensions

Parameters
  • region_identifier (Union[int, Iterable]) – A set of (width, height) coordinates or an indexed region based on region dimensions

  • region_dims (Iterable) – A set of (weight, height) coordinates representing the region dimensions

Returns

A numpy array representative of the pixel region from the image

Return type

np.ndarray

property height

height Get the height property of the image using the adapter’s implementation

Returns

Height in pixels

Return type

int

number_of_regions(region_dims: Iterable)

number_of_regions Calculates the number of regions in the image based on the dimensions of each region

Parameters

region_dims (Iterable) – A set of (width, height) coordinates representing the region dimensions

Returns

The number of regions

Return type

int

region_index_to_coordinates(region_index: int, region_dims: Iterable)

region_index_to_coordinates Converts the index of a region to coordinates of the top-left pixel of the region

Parameters
  • region_index (int) – The nth region of the image (where n >= 0) based on region dimensions

  • region_dims (Iterable) – A set of (width, height) coordinates representing the region dimensions

Returns

A set of (width, height) coordinates representing the top-left pixel of the region

Return type

Iterable

validate_region(region_coordinates: Iterable, region_dims: Iterable) None

validate_region Checks that a region is within the bounds of the image

Parameters
  • region_coordinates (Iterable) – A set of (width, height) coordinates representing the top-left pixel of the region

  • region_dims (Iterable) – A set of (width, height) coordinates representing the region dimensions

Raises
  • IndexError – The top-left pixel or pixel region dimensions are out of the bounds of the image dimensions

  • InvalidCoordinatesException – The top-left pixel was not presented in (width, height) format

  • InvalidDimensionsException – Dimensions of the pixel region were not presented in (width, height) format

property width

width Get the width property of the image using the adapter’s implementation

Returns

Width in pixels

Return type

int

class unified_image_reader.image_reader.ImageReaderDirectory(data: Union[str, list, tuple])

Bases: unified_image_reader.image_reader.ImageReader

Treats a collection of images as a single image whereby regions don’t have locations, only alphabetically-organized indices. This works with both a directory and a list of image files.

property dims

dims Get the width and height property of the image using the adapter’s implementation

Returns

Width and height in pixels

Return type

Iterable

get_region(region_identifier: int, region_dims: Optional[Any] = None) numpy.ndarray

get_region reads in the image at self._region_files[region_identifier]

Parameters
  • region_identifier (int) – the index of the file read (files are indexed alphabetically)

  • region_dims (Any, optional) – IGNORED - the regions will be whatever the regions of the image file are, defaults to None

Raises
  • NotImplementedError – if the region identifier isn’t an index

  • IndexError – if region_identifier isn’t in range

Returns

region (the image in the file in question)

Return type

np.ndarray

property height

height Get the height property of the image using the adapter’s implementation

Returns

Height in pixels

Return type

int

number_of_regions(region_dims: Optional[Any] = None) int

number_of_regions the number of region in the image (in this case, the number of image files)

Parameters

region_dims (Optional[Any], optional) – IGNORED - the dimensions of the regions in this image are the dimensions of the image in the files, defaults to None

Returns

the number of regions in this image (the number of the image files)

Return type

int

property width

width Get the width property of the image using the adapter’s implementation

Returns

Width in pixels

Return type

int

exception unified_image_reader.image_reader.InvalidCoordinatesException

Bases: Exception

exception unified_image_reader.image_reader.InvalidDimensionsException

Bases: Exception

exception unified_image_reader.image_reader.UnsupportedFormatException

Bases: Exception

Module contents