imagecat.operator.util module¶
Functions that produce, consume, and modify Imagecat images.
- imagecat.operator.util.array(ndim=None, shape=None, dtype=None)[source]¶
Factory for parameter converters that return arrays.
- Parameters
ndim (integer, optional) – Raise exceptions if the number of value dimensions don’t match.
shape (integer or tuple of integers, optional) – Raise exceptions if the value shape doesn’t match.
dtype (
numpy.dtype
, optional) – If specified, the returned array will be coerced to the given dtype.
- Returns
converter – Callable that takes a single value as input and produces a
numpy.ndarray
as output.- Return type
callable
- imagecat.operator.util.log_result(log, name, operation, output, **parameters)[source]¶
Standard logging output for operators when they’re executed.
- imagecat.operator.util.optional_image(name, inputs, input)[source]¶
Extract an optional image from task inputs.
- Parameters
name (hashable object, required) – The name of the task being executed.
inputs (Named Inputs, required) – Named inputs containing task function arguments.
input (hashable object, required) – Name of the optional input image.
- Raises
RuntimeError – If inputs contains input, but it isn’t a
imagecat.data.Image
.- Returns
image – The optional image from inputs.
- Return type
class:imagecat.data.Image or
None
- imagecat.operator.util.optional_input(name, inputs, input, *, type=None, default=None)[source]¶
Extract an optional parameter from task inputs.
- Parameters
name (hashable object, required) – The name of the task being executed.
inputs (Named Inputs, required) – Named inputs containing task function arguments.
input (hashable object, required) – Name of the input parameter.
type (callable, optional) – Function for testing / converting the parameter value.
default (Any python object, optional) – Default value that will be returned if inputs doesn’t contain input.
- Returns
parameter – The optional parameter from inputs, or the default value.
- Return type
Any python object.
- imagecat.operator.util.optional_layer(name, inputs, input, *, layer=None, role=None, depth=None, dtype=None)[source]¶
Extract an optional layer from task inputs.
- Parameters
name (hashable object, required) – The name of the task being executed.
inputs (Named Inputs, required) – Named inputs containing task function arguments.
input (hashable object, required) – Name of the optional input image.
layer (
str
, optional) – The name of the optional layer. IfNone
(the default) and the image only contains one layer, use it.role (
imagecat.data.Role
, optional) – If specified, the layer must have a matching role.depth (int, optional) – If specified, the layer must have a matching depth (number of channels).
dtype (
numpy.dtype
, optional) – If specified, the layer must have a matching dtype.
- Returns
layer (
imagecat.data.Layer
orNone
) – The matching layer.
- imagecat.operator.util.require_image(name, inputs, input)[source]¶
Extract an image from task inputs.
- Parameters
name (hashable object, required) – The name of the task being executed.
inputs (Named Inputs, required) – Named inputs containing task function arguments.
input (hashable object, required) – Name of the required input image.
- Raises
RuntimeError – If inputs doesn’t contain the required input.
- Returns
image – The required image from inputs.
- Return type
class:imagecat.data.Image
- imagecat.operator.util.require_input(name, inputs, input, *, type=None)[source]¶
Extract a parameter from task inputs.
- Parameters
name (hashable object, required) – The name of the task being executed.
inputs (Named Inputs, required) – Named inputs containing task function arguments.
input (hashable object, required) – Name of the required input parameter.
type (callable, optional) – Function for testing / converting the type of the input parameter value.
- Raises
RuntimeError – If inputs doesn’t contain the required input.
- Returns
parameter – The required parameter from inputs.
- Return type
Any python object.
- imagecat.operator.util.require_layer(name, inputs, input, *, layer=None, role=None, depth=None, dtype=None)[source]¶
Extract a layer from task inputs.
- Parameters
name (hashable object, required) – The name of the task being executed.
inputs (Named Inputs, required) – Named inputs containing task function arguments.
input (hashable object, required) – Name of the required input image.
layer (
str
, optional) – The name of the required layer. IfNone
(the default) and the image only contains one layer, use it.role (
imagecat.data.Role
, optional) – If specified, the layer must have a matching role.depth (int, optional) – If specified, the layer must have a matching depth (number of channels).
dtype (
numpy.dtype
, optional) – If specified, the layer must have a matching dtype.
- Raises
RuntimeError – If a layer matching all of the criteria can’t be found.
- Returns
layername (
str
) – The name of the matching layer.layer (
imagecat.data.Layer
) – The matching layer.
- imagecat.operator.util.transform(source, target_shape, *, pivot, position, orientation, scale, order)[source]¶
Transform an image using an affine transformation.
- Parameters
source (
numpy.ndarray
, required) – Image to be transformed.target_shape (2-tuple of integers, required) – Desired output image size, as a
(rows, cols)
tuple. Note that this does not have to match the size of the source image. By default, the source image will be centered in the output, cropped if necessary.pivot (2-tuple of numbers, required) – Location of the point on the source image around which scaling and rotation takes place.
orientation (number, required) – Rotation of the source around its pivot point, in degrees. Positive angles lead to counter-clockwise rotation.
position (2-tuple of numbers, required) – Position of the image pivot point relative to target_shape.
scale (2-tuple of numbers, required) – Scale of the source image around its pivot point.
- Returns
rowoffset (integer) – Vertical offset of the returned array relative to the upper-left corner of target_shape
coloffset (integer) – Horizontal offset of the returned array relative to the upper-left corner of target_shape
image (
numpy.ndarray
) – The transformed image.