dcp_server.utils package

Submodules

dcp_server.utils.fsimagestorage module

class dcp_server.utils.fsimagestorage.FilesystemImageStorage(data_config: dict, model_used: str)

Bases: object

Class used for image processing for model inference (prepare image for eval, prepare mask for save).

get_image_size_properties(img: ndarray) None

Set properties of the image size

Parameters:

img (ndarray) – Image (numpy array).

prepare_img_for_eval(img: ndarray) ndarray

Image processing for model inference.

Parameters:

img (np.ndarray) – the image to be processed

Returns:

the loaded and processed image

Return type:

np.ndarray

prepare_mask_for_save(mask: ndarray, channel_ax: int) ndarray

Prepares the mask output of the model to be saved.

Parameters:
  • mask (np.ndarray) – the mask

  • channel_ax (int) – the channel dimension of the mask

Returns:

the ready to save mask

Return type:

np.ndarray

rescale_image(img: ndarray, order: int = 2) ndarray

rescale image

Parameters:
  • img (ndarray) – Image.

  • order (int) – Order of interpolation.

Returns:

Rescaled image.

Return type:

ndarray

resize_mask(mask: ndarray, channel_ax: int | None = None, order: int = 0) ndarray

resize the mask so it matches the original image size

Parameters:
  • mask (ndarray) – Image.

  • height (int) – Height of the image.

  • width (int) – Width of the image.

  • order (int) – From scikit-image - the order of the spline interpolation. Default is 0 if image.dtype is bool and 1 otherwise.

Returns:

Resized image.

Return type:

ndarray

dcp_server.utils.helpers module

dcp_server.utils.helpers.get_file_extension(file: str) str
dcp_server.utils.helpers.get_path_name(filepath: str) str
dcp_server.utils.helpers.get_path_parent(filepath: str) str
dcp_server.utils.helpers.get_path_stem(filepath: str) str
dcp_server.utils.helpers.join_path(root_dir: str, filepath: str) str
dcp_server.utils.helpers.read_config(name: str, config_path: str) dict

Reads the configuration file

Parameters:
  • name (string) – name of the section you want to read (e.g. ‘setup’, ‘eval’)

  • config_path (str) – path to the configuration file

Returns:

dictionary from the config section given by name

Return type:

dict

dcp_server.utils.processing module

dcp_server.utils.processing.convert_to_tensor(imgs: List[ndarray], dtype: type, unsqueeze: bool = True) Tensor

Convert the imgs to tensors of type dtype and add extra dimension if input bool is true.

Parameters:
  • imgs – the list of images to convert

  • dtype (type) – the data type to convert the image tensor

  • unsqueeze (bool) – If True an extra dim will be added at location zero

Returns:

the converted image

Return type:

torch.Tensor

dcp_server.utils.processing.get_objects(mask: ndarray) List

Finds labeled connected components in a binary mask.

Parameters:

mask (numpy.ndarray) – The binary mask representing objects.

Returns:

A list of slices indicating the bounding boxes of the found objects.

Return type:

list

dcp_server.utils.processing.normalise(img: ndarray, norm: str = 'min-max') ndarray

Normalises the image based on the chosen method. Currently available methods are: - min max normalisation.

Parameters:
  • img (np.ndarray) – image to be normalised

  • norm (str) – the normalisation method to apply

Returns:

the normalised image

Return type:

np.ndarray

dcp_server.utils.processing.pad_image(img: ndarray, height: int, width: int, channel_ax: int | None = None, dividable: int = 16) ndarray

Pads the image such that it is dividable by a given number.

Parameters:
  • img (np.ndarray) – image to be padded

  • height (int) – image height

  • width (int) – image width

  • channel_ax (int or None)

  • dividable (int) – the number with which the new image size should be perfectly dividable by

Returns:

the padded image

Return type:

np.ndarray