segment

Author: Chris Dijkstra Date: 10/10/2023

Contains functions for segmenting image arrays.

lettuceSee.segment.elevation_map(rgb_im)

Creates an elevation map of an RGB image by summing the sobel outputs of each channel

Parameters:

rgb_im (ndarray) – 3 dimensional array representing an RGB image

Return type:

ndarray

Returns:

2 dimensional array representing an edge map

lettuceSee.segment.multichannel_threshold(multi_ch_im, x_th=0.0, y_th=0.0, z_th=0.0, inverse=False)

Takes a three-channel image and returns a mask based on thresholds

Parameters:
  • multi_ch_im – a numpy array representing an image with three color channels

  • x_th (float) – the threshold for the first channel, 0.0 by default

  • y_th (float) – the threshold for the second channel, 0.0 by default

  • z_th (float) – the threshold for the third channel, 0.0 by default

  • inverse (bool) – if False pixels below the threshold are marked as 0, if True, pixels above the threshold are marked as 0.

Return type:

ndarray

Returns:

the mask created based on the thresholds, 2D array same width and height as the input

lettuceSee.segment.sh_markers(image, distance=10, bg_mod=0.15, fg_mod=0.2)

Creates marker image based on sobel histogram

Parameters:
  • image (ndarray) – 3d array representing a 3 channel image

  • distance (int) – minimal distance between local maxima and minima

  • bg_mod (float) – modifier for histogram segmentation

  • fg_mod (float) – modifier for histogram segmentation

Return type:

ndarray

Returns:

2D marker image

lettuceSee.segment.shw_segmentation(image, distance=10, bg_mod=0.15, fg_mod=0.2)

Creates binary image through sobel + histogram thresholds + watershed

Parameters:
  • image (ndarray) – array representing a 3d image

  • distance (int) – minimal distance between local maxima and minima

  • bg_mod (float) – modifier for histogram segmentation

  • fg_mod (float) – modifier for histogram segmentation

Return type:

ndarray

Returns:

2D mask for the image

lettuceSee.segment.barb_thresh(im_channel, div=3)

Defines the threshold of an image channel based on its histogram

Parameters:
  • im_channel (ndarray) – 2d array, meant to be hue channel of hsv or a channel of lab

  • div (int) – the divisor used at the end of the algorithm. A higher divisor will lead to a lower threshold

Return type:

float

Returns:

the threshold of the image channel that separates it into healthy and unhealthy tissue

Based on method described in (Barbedo, 2016)

lettuceSee.segment.barb_hue(image, bg_mask=None, div=3)

Takes an image of plant tissue and segments into healthy and brown

Parameters:
  • image (ndarray) – 3d array representing an rgb image

  • bg_mask (ndarray) – 2d array to mask the background

  • div (int) – the divisor used at the end of the algorithm. A higher divisor will lead to a lower threshold

Return type:

ndarray

Returns:

mask with background as 0, healthy tissue as 1 and brown tissue as 2

Based on method described in (Barbedo, 2016)

lettuceSee.segment.canny_labs(image, mask, sigma)

Separates objects trough canny edge detection and then labels the output

Parameters:
  • image (ndarray) – 2d array representing an image

  • mask (ndarray) – 2d binary mask

  • sigma (float) – the sigma used for the gaussian blur component of canny segmentation

Return type:

ndarray

Returns:

labelled image

lettuceSee.segment.centre_primary_label(lab_im, edge_length=200, bg_label=0)

returns the label of the largest object within a central square with ribs of edge_length

Parameters:
  • lab_im (ndarray) – labelled image with only positive values and 0

  • edge_length (int) – height and width of the square used on the centre

  • bg_label (int) – the label number that will be considered background. This can not be chosen as the primary label.

Return type:

ndarray

Returns:

primary label

lettuceSee.segment.central_ob(mask, edge_length=200)

Selects the largest object within a central square with ribs of edge_length

Parameters:
  • mask (ndarray) – 2d array representing a background mask

  • edge_length (int) – height and width of the square considered the centre

Return type:

ndarray

Returns:

2d array representing the input mask with only the largest central object

lettuceSee.segment.canny_central_ob(image, mask, sigma, central_area=200, allowed_deviation=((0.1, 0.1), (0.25, 0.25), (0.25, 0.25)))

Uses canny filter and color channel thresholding to take central object

Parameters:
  • image (ndarray) – 3d array representing color image

  • mask (ndarray) – 2d boolean array representing background mask

  • sigma (float) – sigma used for gaussian blur step of canny edge detection

  • central_area (int) – central area size

  • allowed_deviation (tuple[tuple[int | float, int | float], ...]) – tuple with nested tuple for each channel of an image. Each nested tuple contains the lower and upper deviation allowed for that channel

Return type:

ndarray

Returns:

2d binary mask of central object