Extract Dataset

extract_dataset.py Script to extract leafs and masks to as model inputs

src.helpers.extract_dataset.chip_range(start, end, length, step=1)[source]

A generator which is used to to generate the start and end locations for a to extract a chip for a given image. E.g. for a image of size 1024x1024, the generator will return (0, 512), (512,1024). This is used for a single axis at a time.

Parameters
  • start (int) – the starting location of the where to start tiling from; this is usually set to 0

  • end (int) – the end location where to stop chip; this is usually set to the length of the image at the relevant axis

  • length (int) – the length of the chip

  • step (int) – the size of the step to chip image.

Return type

Tuple[int, int]

Returns

(start pixel, end pixel)

src.helpers.extract_dataset.chip_image(img, x_range, y_range)[source]

Chips a full size image, given tuples containing the x and y ranges of the region to be extracted.

Parameters
  • img (array) – the input image as an np.array

  • x_range (Tuple[int, int]) – tuple containing the x region to chip

  • y_range (Tuple[int, int]) – tuple containing the y region to chip

Return type

array

Returns

an image chip

src.helpers.extract_dataset.pad_chip(img_chip, length_x, length_y, target_colour=0)[source]

Pads an image chip. The padding uses the target colour. This is generally the the colour of the background if padding for a segmentation task

Parameters
  • length_x (int) – the target x length

  • length_y (int) – the target y length

  • img_chip (array) – the image chip to be padded

  • target_colour (int) – the colour to use when padding

Return type

array

Returns

a padded image chip