ops

channel

cv_depot.ops.channel.has_super_brights(image)[source]

Determines if given image has values above 1.0.

Parameters:

image (Image) – Image instance.

Raises:

EnforceError – If image is not an Image instance.

Returns:

Presence of super brights.

Return type:

bool

cv_depot.ops.channel.has_super_darks(image)[source]

Determines if given image has values below 0.0.

Parameters:

image (Image) – Image instance.

Raises:

EnforceError – If image is not an Image instance.

Returns:

Presence of super darks.

Return type:

bool

cv_depot.ops.channel.invert(image)[source]

Inverts the values of the given image. Black becomes white, white becomes black.

Parameters:

image (Image) – Image to be inverted.

Raises:

EnforeError – If image is not an instance of Image.

Returns:

Image

Return type:

image

cv_depot.ops.channel.mix(a, b, amount=0.5)[source]

Mix images A and B by a given amount. An amount of 1.0 means 100% of image A. An amount of 0.0 means 100% of image B.

Parameters:
  • a (Image) – Image A.

  • b (Image) – Image B.

  • amount (float, optional) – Amount of image A. Default: 0.5

Raises:
  • EnforceError – If a is not an Image instance.

  • EnforceError – If b is not an Image instance.

  • EnforceError – If amount is not between 0 and 1.

Returns:

Mixture of A and B.

Return type:

Image

cv_depot.ops.channel.remap(images, channel_map)[source]

Maps many images into a single image according to a given channel map.

Parameters:
  • images (Image, list[Image]) – Images.

  • channel_map (ChannelMap) – Mapping of image channels into output image.

Raises:
  • EnforceError – If images is not an instance of Image or list of Images.

  • EnforceError – If images are not of all the same width and height.

  • EnforceError – If channel_map is not an instance of ChannelMap.

Returns:

Combined image.

Return type:

Image

cv_depot.ops.channel.remap_single_channel(image, channels)[source]

Maps an image with a single channel to an image of a given number of channels.

Parameters:
  • image (Image) – Image to be mapped.

  • channels (list) – List of channel names to map image to.

Raises:
  • EnforceError – If image is not an Image with only one channel.

  • EnforceError – If channels is not a list.

Returns:

Image with given channels.

Return type:

Image

cv_depot.ops.channel.to_hsv(image)[source]

Convert image to hue, saturation, value colorspace.

Parameters:

Image – Image to be converted.

Raises:

AttributeError – If given image does not have RGB channels.

Returns:

Image converted to HSV.

Return type:

Image

cv_depot.ops.channel.to_rgb(image)[source]

Convert image from HSV to RGB.

Parameters:

Image – Image to be converted.

Raises:

AttributeError – If given image does not have RGB channels.

Returns:

Image converted to RGB.

Return type:

Image

draw

cv_depot.ops.draw.annotate(image, mask='a', opacity=0.5, width=10, color='CYAN2', inverse=False, keep_mask=False)[source]

Annotate a given image according to a given mask channel.

Parameters:
  • image (Image) – Image with mask channel.

  • mask (str, optional) – Mask channel. Default: alpha.

  • opacity (float, optional) – Opacity of annotation. Default: 0.5

  • width (int, optional) – Outline width. Default: 10.

  • color (Color or BasicColor, optional) – Color of outline. Default: BasicColor.CYAN2

  • inverse (bool, optional) – Whether to invert the annotation. Default: False.

  • keep_mask (bool, optional) – Whether to keep the mask channel. Default: False.

Returns:

Image with outline.

Return type:

Image

cv_depot.ops.draw.checkerboard(tiles_wide, tiles_high, tile_shape=(10, 10))[source]

Draws a checkerboard of given width, height and tile shape.

Parameters:
  • tiles_wide (int) – Number of tiles wide checkerboard will be.

  • tiles_high (int) – Number of tiles high checkerboard will be.

  • tile_shape (tuple[int], optional) – Width, height tuple of tile shape. Default: (10, 10).

Raises:
  • EnforceError – If tiles_wide is not greater than 0.

  • EnforceError – If tiles_high is not greater than 0.

  • EnforceError – If tile width is not greater than 0.

  • EnforceError – If tile height is not greater than 0.

Returns:

Checkerboard image.

Return type:

Image

cv_depot.ops.draw.grid(image, shape, color='CYAN', thickness=1)[source]

Draws a grid on a given image.

Parameters:
  • image (Image) – Image to be drawn on.

  • shape (tuple[int]) – Width, height tuple.

  • color (Color, optional) – Color of grid. Default: BasicColor.CYAN.

  • thickness (int, optional) – Thickness of grid lines in pixels. Default: 1.

Raises:
  • EnforceError – If image is not an Image instance.

  • EnforceError – If shape is not of length 2.

  • EnforceError – If width or height of shape is less than 0:

  • EnforceError – If color is not an instance of Color or BasicColor.

  • EnforceError – If thickness is not greater than 0.

Returns:

Image with grid.

Return type:

Image

cv_depot.ops.draw.highlight(image, mask='a', opacity=0.5, color='CYAN2', inverse=False)[source]

Highlight a masked portion of a given image according to a given channel.

Parameters:
  • image (Image) – Image to be highlighted.

  • mask (str, optional) – Channel to be used as mask. Default: alpha.

  • opacity (float, optional) – Opacity of highlight overlayed on image. Default: 0.5

  • color (Color or BasicColor, optional) – Color of highlight. Default: BasicColor.CYAN2.

  • inverse (bool, optional) – Whether to invert the highlight. Default: False.

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If mask is not an instance of str.

  • EnforceError – If mask not found in image channels.

  • EnforceError – If opacity is < 0 or > 1.

  • EnforceError – If color is not instance of Color.

  • EnforceError – If inverse is not a boolean.

Returns:

Highlighted image.

Return type:

Image

cv_depot.ops.draw.outline(image, mask='a', width=10, color='CYAN2')[source]

Use a given mask to outline a given image.

Parameters:
  • image (Image) – Image with mask channel.

  • mask (str, optional) – Mask channel. Default: alpha.

  • width (int, optional) – Outline width. Default: 10.

  • color (Color or BasicColor, optional) – Color of outline. Default: BasicColor.CYAN2

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If channel not found in image channels.

  • EnforceError – If width is not >= 0.

  • EnforceError – If color is not an instance of Color or BasicColor.

Returns:

Image with outline.

Return type:

Image

cv_depot.ops.draw.swatch(shape, color, fill_value=0.0, bit_depth=BitDepth.FLOAT32)[source]

Creates an image of the given shape and color.

Parameters:
  • shape (tuple[int]) – List of 3 ints.

  • color (Color) – Color of swatch RGB or L channels.

  • fill_value (float, optional) – Value to fill additional channels with. Default: 0.

  • bit_depth (BitDepth) – Bit depth of swatch. Default: BitDepth.FLOAT32

Raises:
  • EnforceError – If shape is not a tuple of 3 integers.

  • EnforceError – If shape has any zero dimensions.

Returns:

Color swatch.

Return type:

Image

edit

cv_depot.ops.edit.chop(image, channel='a', mode='vertical-horizontal')[source]

Chops up a given image into smaller images that bound single contiguous objects within a given channel.

_images/chop_example.png

Chop has the following modes:

_images/chop_modes.png
Parameters:
  • image (Image) – Image instance.

  • channel (str, optional) – Channel to chop image by. Default: ‘a’.

  • mode (str, optional) –

    The type and order of cuts to ber performed. Default: vertical-horizontal. Options include:

    • vertical - Make only vertical cuts along the width axis.

    • horizontal - Make only horizontal cuts along the height axis.

    • vertical-horizontal - Cut along the width axis first and then

      the height axis of each resulting segement.

    • horizontal-vertical - Cut along the height axis first and then

      the width axis of each resulting segement.

Raises:
  • EnforceError – If image is not an Image or NDArray.

  • EnforceError – If channel is not in image channels.

  • EnforceError – If illegal mode given.

Returns:

Dictionary of form (width, height): Image.

Return type:

dict

cv_depot.ops.edit.crop(image, width_mult, height_mult, width_offset=0, height_offset=0)[source]

Crop a given image according to a width and height multipliers and offsets.

Parameters:
  • image (Image) – Image to be cropped.

  • width_mult (float) – Width multiplier.

  • height_mult (float) – Height multiplier.

  • width_offset (float) – Width offset.

  • height_offset (float) – Height offset.

Raises:
  • EnforeError – If image is not an instance of Image.

  • EnforeError – If width_mult is not > 0 and <= 1.

  • EnforeError – If height_mult is not > 0 and <= 1.

  • EnforceError – If crop dimensions are 0 in width or height.

  • EnforceError – If crop width bounds are outside image dimensions.

  • EnforceError – If crop height bounds are outside image dimensions.

Returns:

Cropped image.

Return type:

Image

cv_depot.ops.edit.cut(image, indices, axis='vertical')[source]

Splits a given image into two images along a vertical or horizontal axis.

_images/cut.png
Parameters:
  • image (Image) – Image to be cut.

  • indices (int or list[int]) – Indices of where to cut along cross-axis.

  • axis (str, optional) – Axis to cut along. Options include: vertical, horizontal. Default: vertical.

Raises:
  • EnforceError – If image is not an Image instance.

  • EnforceError – If indices is not an int or list of ints.

  • EnforceError – If illegal axis is given.

  • IndexError – If indices contains index that is outside of bounds.

Returns:

Two Image instances.

Return type:

tuple[Image]

cv_depot.ops.edit.get_warp_matrix(angle=0, translate_x=0, translate_y=0, scale=1)[source]

Create 3 x 3 warp matrix.

Parameters:
  • angle (float, optional) – Rotation in degrees. Default: 0.

  • translate_x (float, optional) – X translation. Default: 0.

  • translate_y (float, optional) – Y translation. Default: 0.

  • scale (float, optional) – Scale factor. Default: 1.

Returns:

3 x 3 warp matrix.

Return type:

ndarray

cv_depot.ops.edit.pad(image, shape, anchor=Anchor.TOP_LEFT, color='BLACK')[source]

Pads a given image into a new image of a given shape.

The anchor argument determines which corner of the given image will be anchored to the padded images respective corner. For instance, an anchor of ‘top-left’ will anchor the top-left corner of the given image to the top-left corner of the padded image. ‘center-left’ will vertically center the image and horizontally anchor to the left of the image. ‘center-center’ will vertically and horizontally center the image.

Parameters:
  • image (Image) – Image to be padded.

  • shape (tuple[int]) – Shape (width, height, channels) of padded image.

  • anchor (Anchor or str, optional) – Where the given image will be placed within the new image. Default: top-left.

  • color (Color or BasicColor, optional) – Padding color. Default: BasicColor.BLACK

Returns:

Padded image.

Return type:

Image

cv_depot.ops.edit.reformat(image, width, height)[source]

Reformat given image by given width and height factors.

Parameters:
  • image (Image) – Image instance.

  • width (float) – Factor to scale image width by.

  • height (float) – Factor to scale image height by.

Raises:
  • EnforceError – If image is not an Image instance.

  • ValueError – If width or height of reformatted image is less than 1 pixel.

Returns:

Reformatted image.

Return type:

Image

cv_depot.ops.edit.staple(image_a, image_b, direction='right', fill_value=0.0)[source]

Joins two images along a given direction.

_images/staple.png

Images must be the same height if stapling along left/right axis. Images must be the same width if stapling along above/below axis.

Parameters:
  • image_a (Image) – Image A.

  • image_b (Image) – Image B.

  • direction (str, optional) – Where image b will be placed relative to a. Options include: left, right, above, below. Default: right.

  • fill_value (float, optional) – Value to fill additional channels with. Default: 0.

Raises:
  • ValueError – If illegal direction given.

  • ValueError – If direction is left/right and image heights are not equal.

  • ValueError – If direction is above/below and image widths are not equal.

Returns:

Stapled Image.

Return type:

Image

cv_depot.ops.edit.warp(image, angle=0, translate_x=0, translate_y=0, scale=1, inverse=False, matrix=None)[source]

Warp image by given parameters or warp matrix. If matrix is given, parameters are ignored.

Parameters:
  • image (Image) – Image.

  • angle (float, optional) – Rotation in degrees. Default: 0.

  • translate_x (float, optional) – X translation. Default: 0.

  • translate_y (float, optional) – Y translation. Default: 0.

  • scale (float, optional) – Scale factor. Default: 1.

  • inverse (bool, optional) – Inverse transformation. Default: False.

  • matrix (numpy.ndarray, optional) – Warp matrix. Default: None.

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If matrix is not None or an instance of np.ndarray.

  • EnforceError – If matrix is not a 3 x 3 matrix.

Returns:

Warped image.

Return type:

Image

filter

cv_depot.ops.filter.canny_edges(image, size=0)[source]

Apply a canny edge detection to given image.

Parameters:
  • image (Image) – Image.

  • size (int, optional) – Amount of dilation applied to result. Default: 0.

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If size is not an integer >= 0.

Returns:

Edge detected image.

Return type:

Image

cv_depot.ops.filter.gamma(image, value=1.0)[source]

Apply gamma correction to given image.

Parameters:
  • image (Image) – Image to be modified.

  • value (int) – Gamma value. Default: 1.0.

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If value is less than 0.

Returns:

Gamma adjusted image.

Return type:

Image

cv_depot.ops.filter.key_exact_color(image, color, channel='a', invert=False)[source]

Keys given image according to the color of its pixels values. Where that pixel color exactly matches the given color, the mask channel will be 1, otherwise it will be 0.

Parameters:
  • image (Image) – Image to be evaluated.

  • color (Color or BasicColor) – Color to be used for masking.

  • channel (str, optional) – Mask channel name. Default: a.

  • invert (bool, optional) – Whether to invert the mask. Default: False.

Raises:
  • EnforceError – If image is not an Image instance.

  • EnforceError – If channel is not a string.

  • EnforceError – If invert is not a boolean.

  • EnforceError – If RGB is not found in image channels.

Returns:

Image with mask channel.

Return type:

Image

cv_depot.ops.filter.kmeans(image, num_centroids=10, centroids=None, max_iterations=100, accuracy=1.0, epochs=10, seeding='random', generate_report=False)[source]

Applies k-means to the given image.

Parameters:
  • image (Image) – Image instance.

  • num_centroids (int, optional) – Number of centroids to use. Default: 10.

  • centroids (list, optional) – List of triplets. Default: None.

  • max_iterations (int, optional) – Maximum number of k-means updates allowed per centroid. Default: 100.

  • accuracy (float, optional) – Minimum accuracy required of clusters.

  • epochs (int, optional) – Number of times algorithm is applied with different initial labels. Default: 10.

  • seeding (str, optional) – How intial centroids are generated. Default: random. Options include: random, pp_centers.

  • generate_report (bool, optional) – If true returns report in addition to image. Default: False.

Raises:
  • EnforceError – If image is not an Image instance.

  • ValueError – If invalid seeding option is given.

Returns:

K-means image or K-means image and K-means

report.

Return type:

Image or tuple[Image, dict]

cv_depot.ops.filter.linear_lookup(lower=0, upper=1)[source]

Generates a linear lookup table with an upper and lower shoulder.

_images/linear_lut.png
Parameters:
  • lower (float, optional) – Lower shoulder value. Default: 0.

  • upper (float, optional) – Upper shoulder value. Default: 1.

Returns:

Anonymous function that applies lut elementwise to a

given numpy array.

Return type:

numpy.vectorize

cv_depot.ops.filter.linear_smooth(image, blur=3, lower=0, upper=1)[source]

Blur given image then apply linear thresholding it.

Parameters:
  • image (Image) – Image matte to be smoothed.

  • blur (int, optional) – Size of blur. Default: 3.

  • lower (float, optional) – Lower shoulder value. Default: 0.

  • upper (float, optional) – Upper shoulder value. Default: 1.

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If blur is less than 0.

  • EnforceError – If lower or upper is less than 0.

  • EnforceError – If lower or upper is greater than 1.

  • EnforceError – If lower is greater than upper.

Returns:

Smoothed image.

Return type:

Image

cv_depot.ops.filter.tophat(image, amount, kind='open')[source]

Apply tophat morphology operation to given image.

Parameters:
  • image (Image) – Image to be modified.

  • amount (int) – Amount of tophat operation.

  • kind (str, optional) – Kind of operation to be performed. Options include: open, close. Default: open.

Raises:
  • EnforceError – If image is not an instance of Image.

  • EnforceError – If amount is less than 0.

  • EnforceError – If kind is not one of: open, close.

Returns:

Image with tophat operation applied.

Return type:

Image