wsireg.reg_shapes package
Submodules
wsireg.reg_shapes.reg_shapes module
- class wsireg.reg_shapes.reg_shapes.RegShapes(shape_data=None, itk_point_transforms=None, source_res=1, target_res=1, **kwargs)[source]
Bases:
object
Class that holds and manages shape data and it’s transformations in the registration graph
- Parameters:
shape_data (list) – list of np.ndarrays of shape data str - file path to GeoJSON file containing shape data np.ndarray - single shape
itk_point_transforms (list) – list of ITK point transforms, appropriately inverted where non-linear. Usually generated on-the-fly when points are transformed from wsireg transformation data
source_res (float) – isotropic image resolution of the source image in the registration stack, i.e., resolution of the image to which shape data is associated
target_res (float) – isotropic image resolution of the target image in the registration stack usually generated on-the-fly when points are transformed from wsireg transformation data
kwargs – keyword arguments passed to wsireg.utils.tform_utils.shape_reader (shape_name, shape_type)
- shape_data
list of np.ndarrays of shape data str - file path to GeoJSON file containing shape data np.ndarray - single shape
- Type:
list of shape data
- shape_data_gj
shape data in geoJSON dicts
- Type:
list of geoJSON shape data
- transformed_shape_data
numpy shape data that as been tranformed
- Type:
list of shape data
- itk_point_transforms
list of ITK point transforms, appropriately inverted where non-linear. Usually generated on-the-fly when points are transformed from wsireg transformation data
- Type:
list
- source_res
isotropic image resolution of the source image in the registration stack, i.e., resolution of the image to which shape data is associated
- Type:
float
- target_res
isotropic image resolution of the target image in the registration stack usually generated on-the-fly when points are transformed from wsireg transformation data
- Type:
float
- add_shapes(shape_data, **kwargs)[source]
Add shapes via shape_reader, will extend current shape list rather than overwrite it
- Parameters:
shape_data – list of np.ndarrays of shape data str - file path to GeoJSON file containing shape data np.ndarray - single shape
kwargs – keyword arguments passed to wsireg.utils.tform_utils.shape_reader (shape_name, shape_type)
- draw_mask(output_size: Tuple[int, int], transformed: bool = False, labels: bool = False) ndarray [source]
Draw a binary or label mask using shape data.
- Parameters:
output_size (tuple of int) – size of mask in in tuple(x,y)
transformed (bool) – Whether to write transformed shapes to mask or original shapes
labels (bool) – Whether to write each mask instance as a label (1-n_shapes) or to write all as binary (255)
- Returns:
mask – Drawn mask at set output size
- Return type:
np.ndarray
- property n_shapes
Number of shapes loaded
- save_shape_data(output_fp: str | Path, transformed: bool = True) str [source]
Save shape file to GeoJSON on disk.
- Parameters:
output_fp (str) – path to the .json file where shape data will be saved
transformed (bool) – save the transformed shape data or shape data as currently help in memory
- Returns:
output_fp – Path to the saved file
- Return type:
str
- scale_shapes(scale_factor: int | float)[source]
Scale coordinates of list of shape data by scale_factor
- Parameters:
scale_factor (float, int) – isotropic scaling factor for the coordinates
- property shape_names
list of GeoJSON shape names in shape data
- property shape_types
List of GeoJSON shape types in shape data
- transform_shapes(transformations: str | Path | dict | RegTransformSeq, px_idx: bool = True, output_idx: bool = True)[source]
Transform shapes using transformations data from wsireg
- Parameters:
transformations – RegTransformSeq parsable object
px_idx (bool) – whether shape points are specified in physical coordinates (i.e., microns) or in pixel indices
output_idx (bool) – whether transformed shape points should be output in physical coordinates (i.e., microns) or in pixel indices