feature_extraction module

This file contains functions for manually extracting certain properties from pre-processed asparagus pieces and the utility functions that are needed.

feature_extraction.check_purple(img, threshold_purple=6, ignore_pale=0.3)

Checks if an asparagus piece is purple. :param img: A numpy array representing an RGB image where masked out pixels are black. :param threshold_purple: If the histogram of color-hues (0-100) has a peak below this threshold

the piece is considered to be purple.

Parameters

ignore_pale – Don’t consider pixels with a saturation value below ignore_pale

Returns

A boolean that indicates wether the piece is purple or not. list: A list representing the histogram of hues with 100 bins.

Return type

bool

Examples

>>> fig, ax = plt.subplots(2,1,figsize=(14,10))
>>> is_purple, hist_hue_purple = check_purple(image_of_purple_piece)
>>> print(is_purple)
>>> is_purple, hist_hue_white = check_purple(image_of_white_piece)
>>> print(is_purple)
>>> ax[0].plot(hist_hue_purple)
>>> ax[0].plot(hist_hue_white)
>>> ax[1].imshow([np.linspace(0, 1, 256)], aspect='auto', cmap=plt.get_cmap("hsv"))
feature_extraction.curvature_score(img, k)

Returns a score for the curvature of the aparagus piece. A perfectly straight aspargus yields a score of 0 :param img: the image :param k: number of horizontal slices

Returns

standard error of linear regression through the slices

Return type

std_err (float)

feature_extraction.get_horizontal_slices(img, k)

Calculates the x-coordinates of the outline of the asparagus pieces, measured at k evenly spaced horizontal slicing points.

Parameters
  • = the preprocessed image (img) –

  • = the number of slices (k) –

Returns

the slice_points (y-coordinates) an np array([a1, a2],[b1,b2] … ) where a1,a2 = x-coordinates of asparagus outline

feature_extraction.get_length(img)

Simple length extraction The length is measured from the highest white pixel to the lowest in the binarized image after rotation :param img: the image

Returns

the length in millimeters from highest to lowest point, under the assumption that one pixel

corresponds to 4 pixels

Return type

length

feature_extraction.get_width(img, k)

Extract the width at k different rows

Parameters
  • img – the image from which the width should be extracted

  • k – number of rows in which the width should be extracted

Returns

min and max width of the k different rows (# of pixels)

feature_extraction.rust_counter(img, lower=array([50, 42, 31]), upper=array([220, 220, 55]), max_count=30000)

Counts the number of pixels that might be rusty. :param img: image :param lower: lower bound for color range of rust :param upper: upper bound for color range of rust :param max_count: to normalize return value (return value around 0.13 is allready rusty)

Returns

normalized to range from 0 to 1

Return type

value

feature_extraction.zero_crossing(img)

Use zero crossing to detect edges and display them. Filter the image with a laplacian to get an approximation of the second derivate and apply zero crossing. This function does not give a return value, but plots the results for visual inspection. Note: This function was an attempt for flower detection, but it was never finished. :param img: the image

Returns

None