AFL.automation.vision.ImageProcessing#

Reusable image-processing helpers for camera drivers.

The ImageProcessing mixin deliberately does not own a camera or a Driver lifecycle. It can therefore be combined with any driver that stores captured arrays in its dropbox (for example PiCameraDriver).

Classes

Driver(name[, defaults, overrides, ...])

ImageProcessing()

Provide circular ROI, RGB, background, and turbidity processing.

Sequence()

All the operations on a read-only sequence.

class AFL.automation.vision.ImageProcessing.ImageProcessing[source]#

Provide circular ROI, RGB, background, and turbidity processing.

Images are expected to be two-dimensional greyscale arrays or three channel arrays. The array methods are intentionally undecorated so they can also be used directly by a driver implementation. The process_* methods are lightweight, JSON-safe API operations for drivers which also inherit from Driver.

static crop_image(image, row_crop=None, col_crop=None)[source]#

Return a rectangular crop of image after validating its bounds.

static circular_mask(shape, center, radius)[source]#

Create a boolean mask for a circle within a two-dimensional shape.

static find_circular_region(image, hough_radii)[source]#

Locate a circular ROI with a Hough transform.

This optional operation imports scikit-image only when circle detection is requested, keeping ordinary Pi camera capture importable without the vision extra installed.

crop_to_circle(image, center=None, radius=None, hough_radii=None)[source]#

Return an image, circular mask, and circle metadata for a ROI.

center and radius may be supplied explicitly. Otherwise hough_radii is used to detect the circle.

static to_grayscale(image, color_order='RGB')[source]#

Convert a colour image to greyscale, respecting RGB or BGR order.

rgb_values(image, mask=None, color_order='RGB')[source]#

Calculate mean red, green, and blue values, optionally inside mask.

prepare_background(image, row_crop=None, col_crop=None, color_order='RGB')[source]#

Crop and convert a background image into greyscale intensity data.

turbidity_measurement(image, background, mask=None, color_order='RGB')[source]#

Calculate normalized transmission relative to a background image.

The returned turbidity_metric matches the legacy optical-turbidity convention: mean sample intensity divided by background intensity. Lower values therefore indicate a less transmitting (more turbid) sample.

set_background(image_uid)[source]#

Set a retained background image from a previously captured image UID.

measure_mean_rgb(image_uid, center=None, radius=None, hough_radii=None, color_order='RGB', row_crop=None, col_crop=None)[source]#

Return RGB means for a captured image, optionally inside a rectangular and circular ROI.

A rectangular ROI is applied only when both row_crop and col_crop are provided. Circle coordinates and Hough detection are relative to that rectangular crop.

measure_turbidity(image_uid, background_uid=None, center=None, radius=None, hough_radii=None, color_order='RGB', row_crop=None, col_crop=None)[source]#

Return turbidity, optionally inside a rectangular and circular ROI.

A rectangular ROI is applied only when both row_crop and col_crop are provided. The identical crop is applied to the image and its background before circle detection and normalization.