preprocessor_BACKUP_470 module

preprocessor_BACKUP_470.binarize_asparagus_img(img)
preprocessor_BACKUP_470.cut_background(img, background_max_hue, background_min_hue, background_brightness)

Initiates masking in the hsv space.

Cuts out background with specific hue values.

Parameters
  • img (Image) – Image as numpy array

  • background_max_hue (float) – [0-255]

  • background_min_hue (float) – [0-255]

  • background_brightness (float) – [0-255]

Returns

Image without background

Return type

Image

preprocessor_BACKUP_470.filter_mask_img(img)

Opening on the binarized image. :param img: image

Returns

image after opening

Return type

rotated_img

preprocessor_BACKUP_470.preprocessor(img_dir, target_dir, show=True, save=False, debug=True, time_constraint=None, max_width=250, max_height=1200)

Walks over a directory full of images, detects asparagus in those images, extracts them with minimal bounding box into an image of shape height x width and stores that image in target dir with a simple name.

Parameters
  • img_dir – the directory with raw images as string

  • target_dir – the target directory as string (where to store clean images)

  • show – whether to show the generated images

  • save – whether to actually save images or not (for debugging)

  • debug – debug mode: increased verbosity

  • time_constraint – If we expect automatic shutdown by grid service, we set this to the available runtime in minutes. The script will commit suicide gracefully if less than 30 seconds remain. This is only done to prevent being killed by force while the progress file is updated, to prevent catastrophic status loss. (i.e. just set this to 60 if you start this on the grid)

preprocessor_BACKUP_470.verticalize_img(img)

Rotate an image based on its principal axis, makes it upright. :param img: image to be rotated

Returns

image after rotation

Return type

rotated_img