mosaic_grid#
Classes#
This class is used to manage and process mosaic grid images. A mosaic grid is a 2D image containing all the tiles |
Functions#
|
Add a single volume into a mosaic. |
Computes the average blending weights over the mask in ND. |
|
|
Computes the diffusion blending (based on laplace equation) in 2D or 3D. |
|
Resamples a volume / image using ITK. |
Module Contents#
- class mosaic_grid.MosaicGrid(image, tile_shape=(512, 512), overlap_fraction=0.2)[source]#
This class is used to manage and process mosaic grid images. A mosaic grid is a 2D image containing all the tiles for a given mosaic, without any overlap. This class can be used for instance to apply processing to all tiles, to optimize the affine transform matrix describing the tile position, and to stitch the tiles together to obtain the reconstructed mosaic.
Note
This class can only deal with 2D mosaic grids for now. To generate a 2D mosaic grid from a collection of volumetric tiles for a given slice, you can use the script-linum-create-mosaic-grid script.
- Parameters:
image (numpy.ndarray)
tile_shape (tuple)
overlap_fraction (float)
- set_affine(overlap_fraction=0.2)[source]#
Sets the affine matrix given an overlap fraction.
- Parameters:
overlap_fraction (float, optional) – An overlap fraction between 0 and 1, defaults to 0.2
- Return type:
None
- set_blending_method(method='none')[source]#
To set the blending method. Available methodes are ‘none’ and ‘average’, ‘diffusion’.
- Return type:
None
- get_tiles()[source]#
Returns the tiles from the mosaic grid.
- Returns:
tuple containing the tiles and the tile positions in the grid.
- get_neighbors_list(neighborhood_type='N4')[source]#
Returns a list of neighboring tiles.
- Parameters:
neighborhood_type (str) – Type of neighborhood to consider. ‘N4’ for horizontal and vertical neighbors, ‘N8’ to also consider diagonal neighbors.
- Returns:
A list of neighbor pairs given by their grid position.
Note
This also updates the neighbors_list object property.
- get_tile(x, y)[source]#
Extract a tile from the mosaic grid.
- Parameters:
- Returns:
2D tile
- Return type:
- set_tile(x, y, tile)[source]#
Set a tile from the mosaic grid.
- Parameters:
x (int) – x position within the mosaic grid
y (int) – y position within the mosaic grid
tile (numpy.ndarray) – 2D tile
- Return type:
None
- get_position(x, y)[source]#
Compute the cartesian position of a given tile using the internal affine transform.
- Parameters:
- Returns:
(2,) array containing the cartesian position of this tile (in pixel)
- Return type:
- get_neighbor_overlap(n_id)[source]#
Extract the tile overlaps for a given neighbor pair.
- Parameters:
n_id – The neighbor pair id.
- Returns:
(4,) tuple containing (overlap1, overlap2, overlap1_position, overlap2_position)
- crop_tiles(xlim=(0, -1), ylim=(0, -1))[source]#
Crop all tiles in the mosaic grid.
- Parameters:
- Return type:
None
Note
This also resets the affine transform using the overlap_fraction.
- get_stitched_image(blending_method='none')[source]#
Performs a 2D reconstruction of the mosaic grid.
- Parameters:
blending_method (str) – Blending method. Available: ‘none’, ‘average’, ‘diffusion’.
- Returns:
Stitched mosaic.
- Return type:
Note
The affine transform obtained from the overlap fraction or by the affine transform optimization is used for the reconstruction.
- mosaic_grid.addVolumeToMosaic(volume, pos, mosaic, blendingMethod='diffusion', factor=3, width=1.0)[source]#
Add a single volume into a mosaic.
Parameters.#
- volumendarray
Volume to add to the mosaic
- pos(2,) tuple
Position of this volume in mosaic coordinates (XY in pixel)
- mosaicndarray
Mosaic in which the volume is stitched
- blendingMethodstr, optional
Blending method to use (available : ‘diffusion’, ‘average’, ‘none’)
- factorint, optional
Subsampling factor used by the diffusion blending method.
- widthfloat, optional
Blending transition width (between 0 and 1) used by the diffusion blending method, defaults to 1.0.
- returns:
The updated mosaic
- rtype:
ndarray
- mosaic_grid.getAverageBlendingWeights(mask)[source]#
Computes the average blending weights over the mask in ND.
- Parameters:
mask (ndarray) – Bool ndarray describing the overlap.
- Returns:
Blending weights
- Return type:
ndarray
- mosaic_grid.getDiffusionBlendingWeights(fixedMask, movingMask=None, factor=8, nSteps=500.0, convergence_threshold=0.0001, k=1)[source]#
Computes the diffusion blending (based on laplace equation) in 2D or 3D.
- Parameters:
fixedMask (numpy.ndarray) – Fixed volume mask to use as basis for the blending weights
movingMask (numpy.ndarray) – Moving volume data mask. (If none is given, it assumes that the whole volume contains data.)
factor (int) – Subsampling factor
nSteps (int) – Number of diffusion steps.
convergence_threshold (float) – Convergence threshold used to end the diffusion.
k (int) – Structural element radius used to find the boundary of the mask.
- Returns:
ND blending weights.
- Return type:
- mosaic_grid.resampleITK(vol, newshape, interpolator='linear')[source]#
Resamples a volume / image using ITK.
- Parameters:
vol (numpy.ndarray) – 2D/3D array to resample.
newshape (tuple) – New shape of the array, or resampling factor (if a single integer is given)
interpolation – Interpolation method to use. Available are: ‘NN’ (NearestNeighbor) and ‘linear’
interpolator (str)
- Returns:
Resampled array
- Return type: