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 |
Source code in src/careamics/dataset/tiling/lvae_tiled_patching.py
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)). |
Source code in src/careamics/dataset/tiling/lvae_tiled_patching.py
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. |
Source code in src/careamics/dataset/tiling/lvae_tiled_patching.py
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 |
Source code in src/careamics/dataset/tiling/lvae_tiled_patching.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
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. |
Source code in src/careamics/dataset/tiling/lvae_tiled_patching.py
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. |
Source code in src/careamics/dataset/tiling/lvae_tiled_patching.py
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. |