wsireg.reg_images package
RegImage base class
- class wsireg.reg_images.reg_image.NpEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
JSONEncoder
- default(obj)[source]
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class wsireg.reg_images.reg_image.RegImage(preprocessing: ImagePreproParams | Dict | None = None)[source]
Bases:
ABC
Base class for registration images
- cache_image_data(output_dir: str | Path, image_tag: str, check: bool = True) None [source]
Save preprocessed image data to a cache in WsiReg2D. :param output_dir: Where cached data is on disk :type output_dir: path :param image_tag: Tag of the image modality :param check: Whether to check for existence of data :type check: bool
- property channel_axis: int
Axis of the channel dimension.
- property channel_colors: List[str]
Colors of the channels.
- property channel_names: List[str]
Name of the channels of the image.
- check_cache_preprocessing(output_dir: str | Path, image_tag: str)[source]
- Parameters:
output_dir (path) – Where cached data is on disk
image_tag – Tag of the image modality
- Returns:
prepro_flag – Whether a preprocessed version of the image exists in the cache.
- Return type:
bool
- property dask_image: Array
Dask representation of the image.
- property im_dtype: dtype
Data type of image
- property image_res: float | int
Spacing of image pixels (only isotropic right now)
- property is_interleaved: bool
Whether RGB image is interleaved or not.
- property is_rgb: bool
Whether image is RGB or not.
- load_from_cache(output_dir: str | Path, image_tag: str)[source]
Read in preprocessed data from the cache folder. :param output_dir: Where cached data is on disk :type output_dir: path :param image_tag: Tag of the image modality
- Returns:
from_cache_flag – Whether data was read from cache
- Return type:
bool
- static load_orignal_size_transform(output_dir: str | Path, image_tag: str)[source]
Read original size transform from cache.
- Parameters:
output_dir (path) – Where cached data is on disk
image_tag – Tag of the image modality
- Returns:
osize_tform – Original size transform or empty
- Return type:
list
- property mask: Image | <itkTemplate itk::Image> | None
Mask of the image.
- property n_ch: int
Number of channels in image.
- property path: str | Path
Path to image file.
- preprocess_image(reg_image: Image) None [source]
Run full intensity and spatial preprocessing. Creates the reg_image attribute
- Parameters:
reg_image (sitk.Image) – Raw form of image to be preprocessed
- preprocess_reg_image_intensity(image: Image, preprocessing: ImagePreproParams) Image [source]
Preprocess image intensity data to single channel image.
- Parameters:
image (sitk.Image) – reg_image to be preprocessed
preprocessing (ImagePreproParams) – Parameters of the preprocessing
- Returns:
image – Preprocessed single-channel image
- Return type:
sitk.Image
- preprocess_reg_image_spatial(image: Image, preprocessing: ImagePreproParams, imported_transforms=None) Tuple[Image, List[Dict]] [source]
Spatial preprocessing of the reg_image.
- Parameters:
image (sitk.Image) – reg_image to be preprocessed
preprocessing (ImagePreproParams) – Spatial preprocessing parameters
imported_transforms – Not implemented yet..
- Returns:
image (sitk.Image) – Spatially preprcessed image ready for registration
transforms (list of transforms) – List of pre-initial transformations
- property preprocessing: ImagePreproParams | None
Preprocessing params to make reg_image
- read_mask(mask: str | Path | Image | ndarray) Image [source]
Read a mask from geoJSON or a binary image.
- Parameters:
mask (path to image/geoJSON or image) – Data to be used to make the mask, can be a path to a geoJSON or an image file, or a if an np.ndarray, used directly.
- Returns:
mask – Mask image with spacing/size of reg_image
- Return type:
sitk.Image
- property reg_image: Image | <itkTemplate itk::Image>
Preprocessed version of image for registration
- reg_image_sitk_to_itk(cast_to_float32: bool = True) None [source]
Convert SimpleITK to ITK for use in ITKElastix.
- Parameters:
cast_to_float32 (bool) – Whether to make image float32 for ITK, needs to be true for registration.
- property shape: Tuple[int, int, int]
Shape of image file (C,Y,X) or (Y,X,C) if RGB
Submodules
wsireg.reg_images.aics_reg_image module
wsireg.reg_images.czi_reg_image module
- class wsireg.reg_images.czi_reg_image.CziRegImage(image, image_res, mask=None, pre_reg_transforms=None, preprocessing=None, channel_names=None, channel_colors=None)[source]
Bases:
RegImage
wsireg.reg_images.loader module
- wsireg.reg_images.loader.reg_image_loader(image: ndarray | Array | Array | str | Path, image_res: int | float, mask: ndarray | str | Path | None = None, pre_reg_transforms: dict | None = None, preprocessing: ImagePreproParams | None = None, channel_names: List[str] | None = None, channel_colors: List[str] | None = None) TiffFileRegImage | SitkRegImage | NumpyRegImage | CziRegImage [source]
Convenience function to read in images. Determines the correct reader.
- Parameters:
image (str, array-like) – file path to the image to be read or an array like image such as a numpy, dask or zarr array
image_res (float) – spatial resolution of image in units per px (i.e. 0.9 um / px)
mask (Union[str, Path, np.ndarray]) – path to binary mask (>0 is in) image for registration and/or cropping or a geoJSON with shapes that will be processed to a binary mask
pre_reg_transforms (dict) – Pre-computed transforms to be applied to the image prior to registration
preprocessing (ImagePreproParams) – preprocessing parameters for the modality for registration. Registration images should be a xy single plane so many modalities (multi-channel, RGB) must “create” a single channel. Defaults: multi-channel images -> max intensity project image RGB -> greyscale then intensity inversion (black background, white foreground)
channel_names (List[str]) – names for the channels to go into the OME-TIFF
channel_colors (List[str]) – channels colors for OME-TIFF (not implemented)
- Returns:
reg_image – A RegImage subclass for the particular image loaded
- Return type: