quantus.functions.mosaic_func module

This module contains a collection of mosaic creation functions, i.e., group images within a grid structure.

quantus.functions.mosaic_func.build_single_mosaic(mosaic_images_list: List[ndarray]) ndarray

Frame a list of 4 images into a 2x2 mosaic image.

Parameters:
mosaic_images_list: List[np.array]

A list of four images.

Returns:
mosaic: np.ndarray

The single 2x2 mosaic built from a list of images.

quantus.functions.mosaic_func.mosaic_creation(images: ndarray, labels: ndarray, mosaics_per_class: int, seed: int | None = None) Tuple[Any, List[Tuple[Any, ...]], List[Tuple[Any, ...]], List[Tuple[int, ...]], List[Any]]

Build a mosaic dataset from an image dataset (images). Each mosaic corresponds to a 2x2 grid. Each one is composed by four images: two belonging to the target class and the other two are chosen randomly from the rest of the classes.

Parameters:
images: np.ndarray

A np.ndarray which contains the input data.

labels: np.ndarray

A np.ndarray which contains the labels from the input data.

mosaics_per_class: integer

An integer indicating the number of mosaics per class.

seed: integer

An integer used to generate a random number (optional)..

Returns:
all_mosaics: np.ndarray

a np.ndarray which contains the mosaic data

mosaic_indices_list: a List[Tuple[int, int, int, int]] which contains the image indices corresponding to the images

composing each mosaic

mosaic_labels_list (List[Tuple[Union[int, str], …]]): a List[Tuple[Union[int, str], …]] which contains the labels of the images composing each

mosaic. Each tuple contains four values referring to (top_left_label, top_right_label, bottom_left_label, bottom_right_label)

p_batch_list (List[Tuple[int, int, int, int]]): a List[Tuple[int, int, int, int]] which contains the positions of the target class within the mosaic.

Each tuple contains 0 and 1 values (non_target_class and target_class) referring to (top_left, top_right, bottom_left, bottom_right).

target_list (List[Union[int, str]]): a List[Union[int, str]] which contains the target class of each mosaic.