dcnum.segm.segm_torch.torch_preproc

Functions

preprocess_images(images, norm_mean, norm_std[, ...])

Transform image data to something torch models expect

Module Contents

dcnum.segm.segm_torch.torch_preproc.preprocess_images(images: numpy.ndarray, norm_mean: float | None, norm_std: float | None, image_shape: tuple[int, int] | None = None)[source]

Transform image data to something torch models expect

The transformation includes:

  • normalization (division by 255, subtraction of mean, division by std)

  • cropping and padding of the input images to image_shape. For padding, the median of each individual image is used.

  • casting the input images to four dimensions (batch_size, 1, height, width) where the second axis is “channels”

Parameters:
  • images – Input image array (batch_size, height_in, width_in). If this is a 2D image, it will be reshaped to a 3D image with a batch_size of 1.

  • norm_mean – Mean value used for standard score data normalization, i.e. normalized = `(images / 255 - norm_mean) / norm_std; Set to None to disable normalization.

  • norm_std – Standard deviation used for standard score data normalization; Set to None to disable normalization (see above).

  • image_shape – Image shape for which the model was created (height, width). If the image shape does not match the input image shape, then the input images are padded/cropped to fit the image shape of the model.

Returns:

3D array with preprocessed image data of shape (batch_size, 1, height, width)

Return type:

image_proc