wsireg.writers package
Submodules
wsireg.writers.ome_tiff_writer module
- class wsireg.writers.ome_tiff_writer.OmeTiffWriter(reg_image: RegImage, reg_transform_seq: RegTransformSeq | None = None)[source]
Bases:
object
- PhysicalSizeX: int | float | None = None
- PhysicalSizeY: int | float | None = None
- compression: str = 'deflate'
- n_pyr_levels: int | None = None
- pyr_levels: List[Tuple[int, int]] | None = None
- subifds: int | None = None
- tile_size: int = 512
- write_image_by_plane(image_name: str, output_dir: Path | str = '', write_pyramid: bool = True, tile_size: int = 512, compression: str | None = 'default', interpolation: int = 1, blur_size: int = 0, subsample: bool = False) str [source]
Write OME-TIFF image plane-by-plane to disk. WsiReg compatible RegImages all have methods to read an image channel-by-channel, thus each channel is read, transformed, and written to reduce memory during write. RGB images may run large memory footprints as they are interleaved before write, for RGB images, using the OmeTiledTiffWriter is recommended.
- Parameters:
image_name (str) – Name to be written WITHOUT extension for example if image_name = “cool_image” the file would be “cool_image.ome.tiff”
output_dir (Path or str) – Directory where the image will be saved
write_pyramid (bool) – Whether to write the OME-TIFF with sub-resolutions or not
tile_size (int) – What size to write OME-TIFF tiles to disk
compression (str) – tifffile string to pass to compression argument, defaults to “deflate” for minisblack and “jpeg” for RGB type images
- Returns:
output_file_name – File path to the written OME-TIFF
- Return type:
str
- x_size: int | None = None
- x_spacing: int | float | None = None
- y_size: int | None = None
- y_spacing: int | float | None = None
wsireg.writers.tiled_ome_tiff_writer module
- class wsireg.writers.tiled_ome_tiff_writer.OmeTiffTiledWriter(reg_image: RegImage, reg_transform_seq: RegTransformSeq, tile_size: int = 512, zarr_tile_size: int = 2048, moving_tile_padding: int = 128)[source]
Bases:
object
Class for transforming, then writing whole slide images tile-by-tile, allowing memory-efficient transformation of images. The image to be transformed has to have a dask representation that is itself tiled because the writer finds the position of each write tile in fixed space in moving space and reads only the necessary portion of the image to perform the transformation.
Tiles are stored in a temporary zarr store that is deleted after writing to OME-TIFF.
Uses the Tiler library to manage “virtual tiling” for transformation.
- Parameters:
reg_image (RegImage) – wsireg RegImage that has a dask store that is chunked in XY (typical of WSIs) .czi reader does not work!
reg_transform_seq (RegTransformSeq) – wsireg registration transform sequence to be applied to the image
tile_size (int) – Tile size of the output image
zarr_tile_size (int) – Tile used in the zarr intermediate
moving_tile_padding (int) – How much additional padded to pull from moving for each transformed tile This ensures that the interpolation is correctly performed during resampling Non-rigid transforms may need more spacing
- reg_transform_seq
RegTransformSeq to be used in transformation
- Type:
- tile_shape
Shape of OME-TIFF tiles going to disk
- Type:
tuple of ints
- zarr_tile_shape
Shape of zarr tiles going to disk temporarily
- Type:
tuple of ints
- moving_tile_padding
Tile padding use at read in for interpolation
- Type:
int
- property fixed_tile_positions: List[Tuple[int, int, int, int]]
List of tile positions on the fixed image in pixels first np.ndarray is top-left x,y coordinate second np.ndarray is bottom-right x,y coordinate
- property fixed_tile_positions_phys: List[Tuple[float, float, float, float]]
List of tile positions on the fixed image in physical coordinate space first np.ndarray is top-left x,y coordinate second np.ndarray is bottom-right x,y coordinate
- property moving_tile_positions: List[Tuple[int, int, int, int]]
Transformed coordinates of fixed tile positions to moving, pixels first np.ndarray is top-left x,y coordinate second np.ndarray is bottom-right x,y coordinate
- property moving_tile_positions_phys: List[Tuple[float, float, float, float]]
Transformed coordinates of fixed tile positions to moving, physical first np.ndarray is top-left x,y coordinate second np.ndarray is bottom-right x,y coordinate
- set_output_spacing(output_spacing: Tuple[int | float, int | float]) None [source]
Sets the output spacing of the resampled image and will change output shape accordingly :param output_spacing: Spacing of grid for resampling. Will default to target image spacing :type output_spacing: Tuple[Union[int,float], Union[int,float]]
- set_tile_size(tile_size: int) None [source]
Set the internal tile size of the OME-TIFF to be written. :param tile_size: tile size in pixels in x and y for the OME-TIFF :type tile_size: int
- set_zarr_tile_size(tile_size: int) None [source]
Set the tile size for the zarr intermediate. :param tile_size: tile size in pixels in x and y for the temporary zarr store :type tile_size: int
- property tiler: Tiler
Tiler instance to manage fixed output tiling from image shape.
- write_image_by_tile(image_name: str, output_dir: Path | str = '', write_pyramid: bool = True, compression: str | None = 'default', zarr_temp_dir: str | Path | None = None) str [source]
Write images to OME-TIFF from temp zarr store with data.
- Parameters:
image_name (str) – file path stem of the image to be written
output_dir (Union[str,Path]) – directory where image is to be written
write_pyramid (bool) – whether to write a pyramid or single layer
compression (str) – Use compression. “default” will be lossless “deflate” for non-rgb images and “jpeg” for RGB images
zarr_temp_dir (Path or str) – Directory to store the temporary zarr data (mostly used for debugging)
- Returns:
output_file_name – Path to written image file
- Return type:
Path
- write_tiles_to_zarr_store(temp_zarr_store: TempStore, max_workers: int | None = None)[source]
Write tiles to a temporary zarr store.
- Parameters:
temp_zarr_store (zarr.TempStore) – Temporary store where the dataset will go.
- Returns:
resample_zarray – zarr store contained transformed images
- Return type:
zarr.Array
- wsireg.writers.tiled_ome_tiff_writer.compute_sub_res(zarray: Array, pyr_level: int, tile_size: int, is_rgb: bool, im_dtype: dtype) Array [source]
Compute factor-of-2 sub-resolutions from dask array for pyramidalization using dask.
- Parameters:
zarray (da.Array) – Dask array to be downsampled
pyr_level (int) – level of the pyramid. 0 = base, 1 = 2x downsampled, 2=4x downsampled…
tile_size (int) – Size of tiles in dask array after downsampling
is_rgb (bool) – whether dask array is RGB interleaved
im_dtype (np.dtype) – dtype of the output da.Array
- Returns:
resampled_zarray_subres – Dask array (unprocessed) to be written
- Return type:
da.Array
wsireg.writers.merge_ome_tiff_writer module
- class wsireg.writers.merge_ome_tiff_writer.MergeOmeTiffWriter(reg_images: MergeRegImage, reg_transform_seqs: List[RegTransformSeq] | None = None)[source]
Bases:
object
- PhysicalSizeX: int | float | None = None
- PhysicalSizeY: int | float | None = None
- compression: str = 'deflate'
- merge_write_image_by_plane(image_name: str, sub_image_names: List[str], output_dir: Path | str = '', write_pyramid: bool = True, tile_size: int = 512, compression: str | None = 'default') str [source]
Write merged OME-TIFF image plane-by-plane to disk. RGB images will be de-interleaved with RGB channels written as separate planes.
- image_name: str
Name to be written WITHOUT extension for example if image_name = “cool_image” the file would be “cool_image.ome.tiff”
- sub_image_names: list of str
Names added before each channel of a given image to distinguish it.
- output_dir: Path or str
Directory where the image will be saved
- write_pyramid: bool
Whether to write the OME-TIFF with sub-resolutions or not
- tile_size: int
What size to write OME-TIFF tiles to disk
- compression: str
tifffile string to pass to compression argument, defaults to “deflate” for minisblack and “jpeg” for RGB type images
- output_file_name: str
File path to the written OME-TIFF
- n_pyr_levels: int | None = None
- pyr_levels: List[Tuple[int, int]] | None = None
- subifds: int | None = None
- tile_size: int = 512
- x_size: int | None = None
- x_spacing: int | float | None = None
- y_size: int | None = None
- y_spacing: int | float | None = None