torch_staintools.hash package
Submodules
torch_staintools.hash.color module
- torch_staintools.hash.color.od_angle_hash64(od: Tensor, mask: Tensor | None = None) Tensor
Compute the 64bit hash from od angles.
- Parameters:
od
mask – target masking area for tissue foreground. If None then all regions are considered tissue.
- Returns:
the hash
- Return type:
torch.Tensor
torch_staintools.hash.dhash module
- torch_staintools.hash.dhash.od_dhash(od: Tensor, out_h: int = 8, out_w: int = 8) tuple[Tensor, Tensor]
torch_staintools.hash.hash_util module
- torch_staintools.hash.hash_util.pack_bits_u64(bits: Tensor) Tensor
bits * weight may cause overflow in some rare case.
- Parameters:
bits
- Returns:
B-dimensional uint64
- Return type:
torch.Tensor
torch_staintools.hash.key module
- torch_staintools.hash.key.key_from_od(od: Tensor, mask: Tensor) List[Tuple[int, int, bytes, int]]
- torch_staintools.hash.key.lbp_code_to_bytes(lbp_code: Tensor) List[bytes]
- Parameters:
lbp_code – B x R x D. R as number of regions. D can be: 256: all 8-neighborhood encoding 59: uniform pattern 10: rotation invariance
- Returns:
List of bytes. Each element is a bytes array corresponding to the hash of a data point in the batch.
- torch_staintools.hash.key.to_uint(h: Tensor) List[int]
torch_staintools.hash.lbp module
- torch_staintools.hash.lbp.hist_lbp8_256_to_59(code_f: Tensor, lut: Tensor) Tensor
Uniform pattern compression. 256 -> 59
- Parameters:
code_f – flattened LBP codes. B x num_regions x 256.
lut – Look-up table. 256-D
- Returns:
histogram. B x num_regions x 59 (uint16).
- Return type:
torch.Tensor
- torch_staintools.hash.lbp.od_lbp8_hash(od: Tensor, thumb_size: int = 32, grid_h: int = 1, grid_w: int = 1, use_riu: bool = True, levels: int | None = 16, use_sqrt: bool = True) Tensor
- Parameters:
od – Input batch image in optical density. BxCxHxW.
thumb_size – size of the code thumbnail.
grid_h – grid height. how many regions along H. (region height = thumb // grid_height)
grid_w – grid width. how many regions along W. (region width = thumb // grid_width)
use_riu – whether further cast to RIU (10bytes)
levels – number of quantization levels. If None, them bypass.
use_sqrt – whether to further compress the frequency by sqrt.
- Returns:
- the histogram. B x (grid_h*grid_w) * D
grid_h*grid_w as how many grids; D = 256 -> original LBP (8bits) D = 59 -> Uniform Pattern
- Return type:
torch.Tensor
- torch_staintools.hash.lbp.u2_hist59_to_riu2_hist10(hist59: Tensor, lut_riu: Tensor) Tensor
map the u2 (uniform pattern, 59) to riu (rotation-invariance, 10)
- Parameters:
hist59
lut_riu
Returns: