histo_kit.utils.file_utils¶
Functions
|
Create a folder within a parent directory if it does not already exist. |
|
Get the base name of a file without its extension. |
|
Rescale and save an image to the specified path. |
- histo_kit.utils.file_utils.create_folder(parent, folder_name)[source]¶
Create a folder within a parent directory if it does not already exist.
- Parameters:
parent (str) – Path to the parent directory where the new folder should be created.
folder_name (str) – Name of the folder to create.
- Returns:
The function creates the folder on disk and returns the path to the created folder.
- Return type:
str or Path
Notes
If the folder already exists, it will not be recreated.
- histo_kit.utils.file_utils.get_basename(path)[source]¶
Get the base name of a file without its extension.
- Parameters:
path (str or Path) – Full path to the file.
- Returns:
The base name of the file (filename without extension).
- Return type:
str
Examples
>>> get_basename("/home/user/image.v1.test.tiff") 'image.v1.test'
- histo_kit.utils.file_utils.save_rescaled(image, new_size, save_path, rescale_method=1, mode='RGB', writer='PIL')[source]¶
Rescale and save an image to the specified path.
- Parameters:
image (numpy.ndarray or PIL.Image.Image) – Input image to be rescaled. If a NumPy array is provided, it will be converted to a PIL image.
new_size (tuple of int) – Target size of the rescaled image in the form (width, height).
save_path (str or Path) – Path where the rescaled image will be saved.
rescale_method (int, optional) – Resampling method used for resizing (default is
Image.LANCZOS, for other methods refer to PIL documentation).mode (str, optional) – Color mode to convert the image to (default is
'RGB', for grayscale use'L', for binary use'1'for other options refer to the PIL documentation).
- Returns:
The rescaled image object.
- Return type:
PIL.Image.Image
Notes
The function saves the rescaled image to disk and returns the resulting PIL image instance.