microglia_analyzer.tiles.tiler module
- class microglia_analyzer.tiles.tiler.ImageTiler2D(patch_size, overlap, shape, blending='gradient')[source]
Bases:
object
- image_to_tiles(image, use_normalize=True, lower_bound=0.0, upper_bound=1.0, dtype=<class 'numpy.float32'>)[source]
Takes an image and cuts it into tiles according to the layout processed for this shape. The image is not modified. Works with any number of channels. The produced tiles have the possibility to be normalized in any desired range.
- Parameters:
image – (np.ndarray) Image to cut into patches.
use_normalize – (bool) Whether to normalize the image or not (not destructive).
lower_bound – (float) Lower bound of the normalization.
upper_bound – (float) Upper bound of the normalization.
dtype – (np.dtype) Type of the output tiles.
- Returns:
(list) List of patches (np.ndarray) cut from the image.
- Return type:
patches
- tiles_to_image(patches)[source]
Takes a list of tiles (images) and uses the coefs maps to fusion them into a single image with a smooth blending. The goal is to assemble them with seamless blending, respecting the overlap. The order in the list must match the order of the layout. Input patches are not modified. Works with any number of channels.
- Parameters:
patches – (list) List of patches (np.ndarray) to merge.
- Returns:
(np.ndarray) Merged
- Return type:
canvas
- microglia_analyzer.tiles.tiler.make_gradient_patch(patch_size, overlap, direction)[source]
Builds a patch containing coefficients between 0 and 1 so it can be used to merge patches. The area not included in the overlap is filled with 1s, while a linear gradient from 1 to 0 is applied to the overlap area. The direction of the gradient is defined by the direction parameter, respecting the following order: [0: LEFT, 1: BOTTOM, 2: RIGHT, 3: TOP] The provided patch_size is the final size of the patch, including the overlap.
- Parameters:
patch_size – (int) Size of the patch (height and width), overlap included.
overlap – (int) Overlap between patches (in pixels).
direction – (int) Direction of the gradient. 0: LEFT, 1: BOTTOM, 2: RIGHT, 3: TOP
- Returns:
(np.ndarray) Patch containing the coefficients.
- Return type:
patch
- microglia_analyzer.tiles.tiler.normalize(image, lower_bound=0.0, upper_bound=1.0, dtype=<class 'numpy.float32'>)[source]
Normalizes the value of an image between lower_bound and upper_bound. Works whatever the number of channels. The normalization is not applied in place.
- Parameters:
image – (np.ndarray) Image to normalize.
lower_bound – (float) Lower bound of the normalization.
upper_bound – (float) Upper bound of the normalization.
dtype – (np.dtype) Type of the output image.
- Returns:
(np.ndarray) Normalized image.
- Return type:
img