Module qute.data.utils
Utilities.
Functions
def qute_to_msd_format(input_folder: Union[pathlib.Path, str], output_folder: Union[pathlib.Path, str], channel_names: tuple = ('fluorescence_microscopy',), label_names: tuple = ('background', 'cell', 'cell_border'), dataset_id: int = 1, dataset_name: Optional[str] = None, stem_name: str = 'demo_', images_suffix: str = '_0000', to_nii_gz: bool = False, test_perc: float = 0.2, num_folds: int = 5, force: bool = False, seed=None) ‑> tuple[bool, str]-
Convert a qute dataset (with sub-folders "images" and "labels") to an MSD dataset.
Make sure the images and labels have ONE numerical index only and that each is unique.
Parameters
input_folder:Union[Path, str]- Full path of the dataset in qute format.
output_folder:Union[Path, str]- Full path of the nnUnetv2-compatible dataset. It is recommended to set this to
$nnNet_raw. channel_names:tuple- Name of the channels, e.g. ("fluorescence_microscopy", )
label_names:tuple- Name of the segmentation classes, e.g. ("background", "cell", "cell_border")
dataset_id:int- Integer ID of the dataset.
dataset_name:str- Name of the dataset. If not specified, it will be derived from
input_folder. stem_name:str- Stem name of all images. In contrast to the qute format, all training images, labels and test images must have the same stem name.
images_suffix:str (default is "_0000")- Numeric suffix (as 0-padded string and leading _) for the images (it won't be applied to the labels). For instance, imagesTr/demo_001_0000.tif is matched by labelsTr/demo_001.tif.
to_nii_gz:bool (default is False)- Set to True to convert the TIFF images to nii.gz; otherwise, the TIFF files are just copied over.
test_perc:float (default is 0.2)- Fraction of the images to be used for testing.
num_folds:int (default is 5)- Number of folds for k-fold cross-validation during training.
force:bool (default is False)- Set to True to delete and recreate if a converted Dataset already exists in the
output_folder, otherwise abort. seed:int (default is 2022)- Seed for the random number generator (for training/test splitting).
Returns
res,msg:tuple(bool, str)- res: True if the dataset was created, False otherwise msg: "" if successful; otherwise, contains error message.
def sample(image: numpy.ndarray, patch_size: tuple, y0: Optional[int] = None, x0: Optional[int] = None, seed: Optional[int] = None) ‑> tuple[numpy.ndarray, int, int]-
Returns a (random) subset of given shape from the passed 2D image.
Parameters
image:numpy array- Original intensity image.
patch_size:tuple- Size (y, x) of the subset of the image to be randomly extracted.
y0:Optional[int]- y component of the top left corner of the extracted region. If omitted (default), it will be randomly generated.
x0:Optional[int]- x component of the top left corner of the extracted region. If omitted (default), it will be randomly generated.
seed:Optional[int]- Random generator seed to reproduce the sampling. Omit to create a new random sample every time.
Returns
result:tuple[np.ndarray, int, int]- Subset of the image of given size; y coordinate of the top-left corner of the extracted subset; x coordinate of the top-left corner of the extracted subset.