viqa.utils.load_data¶
- viqa.utils.load_data(img: ndarray | ImageArray | Tensor | str | PathLike, data_range: int | None = None, normalize: bool = False, batch: bool = False, roi: list[Tuple[int, int]] | None = None) list[ImageArray] | ImageArray [source]¶
Load data from a numpy array, a pytorch tensor or a file path.
- Parameters:
img (np.ndarray, viqa.ImageArray, torch.Tensor, str or os.PathLike) – Numpy array, ImageArray, tensor or file path
data_range (int, optional, default=None) – Maximum value of the returned data. Passed to
viqa.utils.normalize_data()
.normalize (bool, default False) – If True, data is normalized to (0,
data_range
) based on min and max of img.batch (bool, default False) –
If True, img is a file path and all files in the directory are loaded.
Deprecated since version 4.0.0: This will be deprecated in version 4.0.0.
roi (list[Tuple[int, int]], optional, default=None) – Region of interest for cropping the image. The format is a list of tuples with the ranges for the x, y and z axis. If not set, the whole image is loaded.
- Returns:
img_arr –
viqa.utils.ImageArray
or list ofviqa.utils.ImageArray
containing the data- Return type:
ImageArray or list[ImageArray]
- Raises:
ValueError – If input type is not supported If
data_range=None
andnormalize=True
- Warns:
RuntimeWarning – If
data_range
is set butnormalize=False
.data_range
will be ignored.
Warning
batch
will be deprecated in version 4.0.0.Examples
>>> from viqa import load_data >>> path_r = "path/to/reference/image.mhd" >>> path_m = "path/to/modified/image.mhd" >>> img_r = load_data(path_r) >>> img_m = load_data(path_m)
>>> from viqa import load_data >>> img_r = np.random.rand(128, 128) >>> img_r = load_data(img_r, data_range=255, normalize=True)