linumpy.mosaic.grid#
Mosaic grid management and stitching utilities.
Classes#
Manage and process mosaic grid images. |
Functions#
|
Add a single volume into a mosaic. |
Compute the average blending weights over the mask in ND. |
|
|
Compute the diffusion blending (based on laplace equation) in 2D or 3D. |
Module Contents#
- class linumpy.mosaic.grid.MosaicGrid(image, tile_shape=(512, 512), overlap_fraction=0.2)[source]#
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
linum_create_mosaic_grid_3dscript.- Parameters:
image (numpy.ndarray)
tile_shape (tuple | collections.abc.Sequence)
overlap_fraction (float)
- set_affine(overlap_fraction=0.2)[source]#
Set the affine matrix given an overlap fraction.
- Parameters:
overlap_fraction (float, optional) – An overlap fraction between 0 and 1, by default 0.2.
- Return type:
None
- set_blending_method(method='none')[source]#
To set the blending method. Available methodes are ‘none’ and ‘average’, ‘diffusion’.
- Parameters:
method (str)
- Return type:
None
- get_tiles()[source]#
Return the tiles from the mosaic grid.
- Returns:
Tiles and tile positions in the grid.
- Return type:
- get_neighbors_around_tile(x, y, neighborhood_type='N4')[source]#
Return all neighboring tiles around a given tile position.
- get_neighbors_list(neighborhood_type='N4')[source]#
Return a list of neighboring tiles.
- Parameters:
neighborhood_type (str, optional) – 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.
- Return type:
Notes
This also updates the neighbors_list object property.
- get_position(x, y)[source]#
Compute the cartesian position of a given tile using the internal affine transform.
- get_neighbor_overlap_from_pos(p1, p2)[source]#
Compute the overlapping regions between two tiles given their positions.
- Parameters:
p1 (collections.abc.Sequence[int] | numpy.ndarray)
p2 (collections.abc.Sequence[int] | numpy.ndarray)
- Return type:
- crop_tiles(xlim=(0, -1), ylim=(0, -1))[source]#
Crop all tiles in the mosaic grid.
- Parameters:
- Return type:
None
Notes
This also resets the affine transform using the overlap_fraction.
- get_stitched_image(blending_method='none')[source]#
Perform a 2D reconstruction of the mosaic grid.
- Parameters:
blending_method (str, optional) – Blending method. Available: ‘none’, ‘average’, ‘diffusion’.
- Returns:
Stitched mosaic.
- Return type:
ndarray
Notes
The affine transform obtained from the overlap fraction or by the affine transform optimization is used for the reconstruction.
- global_overlap_similarity(random_fraction=1.0, threshold=None)[source]#
Compute a global overlap similarity error across all tile pairs.
- optimize_overlap(step=0.01, omin=0.1, omax=0.5, display=False, random_fraction=1.0, threshold=None)[source]#
Use the similarity between every neighboring tiles to estimate the overlap fraction.
- Parameters:
step (float, optional) – Overlap fraction steps used for the search.
omin (float, optional) – Minimum overlap fraction to consider.
omax (float, optional) – Maximum overlap fraction to consider.
display (bool, optional) – If set to true, the similarity curve will be displayed at the end of the optimization.
random_fraction (float, optional) – Fraction of tiles to use for the similarity computation, by default 1.0.
threshold (float, optional) – Threshold for the similarity computation, by default None.
- Return type:
None
- linumpy.mosaic.grid.add_volume_to_mosaic(volume, pos, mosaic, blending_method='diffusion', factor=3, width=1.0)[source]#
Add a single volume into a mosaic.
- Parameters:
volume (ndarray) – Volume to add to the mosaic
pos ((2,) tuple) – Position of this volume in mosaic coordinates (XY in pixel)
mosaic (ndarray) – Mosaic in which the volume is stitched
blending_method (str, optional) – Blending method to use (available : ‘diffusion’, ‘average’, ‘none’)
factor (int, optional) – Subsampling factor used by the diffusion blending method.
width (float, optional) – Blending transition width (between 0 and 1) used by the diffusion blending method, defaults to 1.0.
- Returns:
The updated mosaic
- Return type:
ndarray
- linumpy.mosaic.grid.get_average_blending_weights(mask)[source]#
Compute the average blending weights over the mask in ND.
- Parameters:
mask (ndarray) – Bool ndarray describing the overlap.
- Returns:
Blending weights.
- Return type:
ndarray
- linumpy.mosaic.grid.get_diffusion_blending_weights(fixed_mask, moving_mask=None, factor=8, n_steps=500, convergence_threshold=0.0001, k=1)[source]#
Compute the diffusion blending (based on laplace equation) in 2D or 3D.
- Parameters:
fixed_mask (ndarray) – Fixed volume mask to use as basis for the blending weights.
moving_mask (ndarray, optional) – Moving volume data mask. If none is given, it assumes that the whole volume contains data.
factor (int, optional) – Subsampling factor.
n_steps (int, optional) – Number of diffusion steps.
convergence_threshold (float, optional) – Convergence threshold used to end the diffusion.
k (int, optional) – Structural element radius used to find the boundary of the mask.
- Returns:
ND blending weights.
- Return type:
ndarray