Interfaces
Here we list and briefly describe the high level algorithm interfaces which the SMQTK-Image-IO package provides. There is at least one implementation available for each interface. Some implementations will require additional dependencies that cannot be packaged with SMQTK.
ImageReader
- class smqtk_image_io.interfaces.image_reader.ImageReader[source]
Interface for algorithms that load a raster image matrix from a data element.
- is_valid_element(data_element: DataElement) bool[source]
Check if the given DataElement instance reports a content type that matches one of the MIME types reported by
valid_content_types.This override checks if the
DataElementhas thematrixproperty as theMatrixDataElementwould provide, and that its value of an expected type.- Parameters:
data_element (smqtk.representation.DataElement) – Data element instance to check.
- Returns:
True if the given element has a valid content type as reported by
valid_content_types, and False if not.- Return type:
bool
- load_as_matrix(data_element: DataElement, pixel_crop: AxisAlignedBoundingBox | None = None) ndarray | None[source]
Load an image matrix from the given data element.
Matrix Property Shortcut. If the given DataElement instance defines a
matrixproperty this method simply returns that. This is intended to interface with instances ofsmqtk.representation.data_element.matrix.MatrixDataElement.Loading From Bytes. When not loading from a short-cut matrix, matrix return format is
ImageReaderimplementation dependant. Implementations of this interface should specify and describe their return type.Aside from the exceptions documented below, other exceptions may be raised when an image fails to load that are implementation dependent.
- Parameters:
data_element (smqtk.representation.DataElement) – DataElement to load image data from.
pixel_crop (None|smqtk.representation.AxisAlignedBoundingBox) – Optional bounding box specifying a pixel sub-region to load from the given data. If this is provided it must represent a valid sub-region within the loaded image, otherwise a RuntimeError is raised. Handling of non-integer aligned boxes are implementation dependant.
- Raises:
RuntimeError – A crop region was specified but did not specify a valid sub-region of the image.
AssertionError – The
data_elementprovided defined amatrixattribute/property, but its access did not result in an expected value.ValueError –
- This error is raised when:
The given
data_elementwas not of a valid content type.A
pixel_cropbounding box was provided but was zero volume.pixel_cropbounding box vertices are not fully represented by integers.
- Returns:
Numpy ndarray of the image data. Specific return format is implementation dependant.
- Return type:
numpy.ndarray