torch_staintools.functional.utility package
Submodules
torch_staintools.functional.utility.implementation module
- torch_staintools.functional.utility.implementation.default_device(device: device | None = None) device | None
Default device if device is not given.
- Parameters:
device – input device.
- Returns:
torch.device(‘cpu’) if None, otherwise the input device itself.
- torch_staintools.functional.utility.implementation.default_rng(rng: Generator | int | None, device: device | None) Generator | None
Helper function to get the default random number generator (torch.Generator)
- Parameters:
rng – Optional. int seed or torch.Generator. If not set (None) then return None. Identity mapping if input is already a generator. Create a new generator and specify the seed if an int seed is given.
device – device of the rng
- Returns:
torch.Generator
- torch_staintools.functional.utility.implementation.img_from_concentration(concentration: Tensor, stain_matrix: Tensor, img_shape: Tuple[int, ...], out_range: Tuple[float, float] = (0, 1))
reconstruct image from concentration and stain matrix to RGB
- Parameters:
concentration – B x (HW) x num_stain
stain_matrix – B x num_stain x input channel
img_shape –
out_range –
Returns:
- torch_staintools.functional.utility.implementation.nanstd(data: Tensor, dim: int | tuple | None = None, correction: float = 1) Tensor
Compute the standard deviation while ignoring NaNs.
Always keep the dim.
- Parameters:
data – Input tensor.
dim – The dimension or dimensions to reduce. If None (default), reduces all dimensions.
correction – Difference between the sample size and sample degrees of freedom. Defaults 1 (Bessel’s).
- Returns:
Standard deviation with NaNs ignored. If dim is provided, it reduces along that dimension(s), otherwise reduces all dimensions.
- Return type:
torch.Tensor
- torch_staintools.functional.utility.implementation.transpose_trailing(mat: Tensor)
Helper function to transpose the trailing dimension, since data is batchified.
- Parameters:
mat – input tensor ixjxk
- Returns:
output with flipped dimension from ixjxk –> ixkxj