LVAE Tiled Patching
Functions to reimplement the tiling in the Disentangle repository.
compute_padding(data_shape, tile_size, overlaps)
Calculate padding to ensure stitched data comes from the center of a tile.
Padding is added to an array with shape data_shape so that when tiles are
stitched together, the data used always comes from the center of a tile, even for
tiles at the boundaries of the array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_shape
|
1D numpy.array of int
|
The shape of the data to be tiled and stitched together, (S, C, (Z), Y, X). |
required |
tile_size
|
1D numpy.array of int
|
The tile size in each dimension, ((Z), Y, X). |
required |
overlaps
|
1D numpy.array of int
|
The tile overlap in each dimension, ((Z), Y, X). |
required |
Returns:
| Type | Description |
|---|---|
tuple of (int, int)
|
A tuple specifying the padding to add in each dimension, each element is a two
element tuple specifying the padding to add before and after the data. This
can be used as the |
compute_tile_grid_shape(data_shape, tile_size, overlaps)
Calculate the number of tiles in each dimension.
This can be thought of as a grid of tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_shape
|
1D numpy.array of int
|
The shape of the data to be tiled and stitched together, (S, C, (Z), Y, X). |
required |
tile_size
|
1D numpy.array of int
|
The tile size in each dimension, ((Z), Y, X). |
required |
overlaps
|
1D numpy.array of int
|
The tile overlap in each dimension, ((Z), Y, X). |
required |
Returns:
| Type | Description |
|---|---|
tuple of int
|
The number of tiles in each direction, ((Z, Y, X)). |
compute_tile_info(tile_grid_indices, data_shape, tile_size, overlaps, sample_id=0)
Compute the tile information for a tile with the coordinates tile_grid_indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_grid_indices
|
1D np.array of int
|
The coordinates of the tile within the tile grid, ((Z), Y, X), i.e. for 2D tiling the coordinates for the second tile in the first row of tiles would be (0, 1). |
required |
data_shape
|
1D np.array of int
|
The shape of the data, should be (C, (Z), Y, X) where Z is optional. |
required |
tile_size
|
1D np.array of int
|
Tile sizes in each dimension, of length 2 or 3. |
required |
overlaps
|
1D np.array of int
|
Overlap values in each dimension, of length 2 or 3. |
required |
sample_id
|
int
|
An ID to identify which sample a tile belongs to. |
0
|
Returns:
| Type | Description |
|---|---|
TileInformation
|
Information that describes how to crop and stitch a tile to create a full image. |
compute_tile_info_legacy(grid_index_manager, index)
Compute the tile information for a tile at a given dataset index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_index_manager
|
GridIndexManager
|
The grid index manager that keeps track of tile locations. |
required |
index
|
int
|
The dataset index. |
required |
Returns:
| Type | Description |
|---|---|
TileInformation
|
Information that describes how to crop and stitch a tile to create a full image. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
extract_tiles(arr, tile_size, overlaps, padding_kwargs=None)
Generate tiles from the input array with specified overlap.
The tiles cover the whole array; which will be additionally padded, to ensure that the section of the tile that contributes to the final image comes from the center of the tile.
The method returns a generator that yields tuples of array and tile information, the latter includes whether the tile is the last one, the coordinates of the overlap crop, and the coordinates of the stitched tile.
Input array should have shape SC(Z)YX, while the returned tiles have shape C(Z)YX, where C can be a singleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray
|
Array of shape (S, C, (Z), Y, X). |
required |
tile_size
|
1D numpy.ndarray of tuple
|
Tile sizes in each dimension, of length 2 or 3. |
required |
overlaps
|
1D numpy.ndarray of tuple
|
Overlap values in each dimension, of length 2 or 3. |
required |
padding_kwargs
|
dict
|
The arguments of |
None
|
Yields:
| Type | Description |
|---|---|
Generator[Tuple[ndarray, TileInformation], None, None]
|
Tile generator, yields the tile and additional information. |
n_tiles_1d(axis_size, tile_size, overlap)
Calculate the number of tiles in a specific dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_size
|
int
|
The length of the data for in a specific dimension. |
required |
tile_size
|
int
|
The length of the tiles in a specific dimension. |
required |
overlap
|
int
|
The tile overlap in a specific dimension. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of tiles that fit in one dimension given the arguments. |
total_n_tiles(data_shape, tile_size, overlaps)
Calculate The total number of tiles over all dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_shape
|
1D numpy.array of int
|
The shape of the data to be tiled and stitched together, (S, C, (Z), Y, X). |
required |
tile_size
|
1D numpy.array of int
|
The tile size in each dimension, ((Z), Y, X). |
required |
overlaps
|
1D numpy.array of int
|
The tile overlap in each dimension, ((Z), Y, X). |
required |
Returns:
| Type | Description |
|---|---|
int
|
The total number of tiles over all dimensions. |