gridgene.overlay module#
- gridgene.overlay.timeit(func)[source]
- class gridgene.overlay.Overlay(mask_dict, segmentation, segmentation_type='auto', save_path=None, min_x=0, min_y=0, flip_masks=True, logger=None)[source]
Bases:
objectOverlay segmentation with binary masks for comparison and visualization.
Supports polygon-based and label-mask segmentations.
- Parameters:
mask_dict (dict[str, np.ndarray]) – Dictionary of masks, where keys are mask names and values are binary mask arrays.
segmentation (dict or np.ndarray or SpatialData) – Segmentation data, either GeoJSON-like dict, label mask ndarray, or SpatialData.
segmentation_type ({'auto', 'polygons', 'label_mask'}, optional) – Type of segmentation input. Default is ‘auto’ to detect automatically.
save_path (str, optional) – Optional path to save visualizations.
min_x (float, optional) – Minimum x coordinate to shift polygons. Default is 0.
min_y (float, optional) – Minimum y coordinate to shift polygons. Default is 0.
flip_masks (bool, optional) – Whether to flip masks vertically and rotate. Default is True.
logger (logging.Logger, optional) – Custom logger. If None, a default logger is used.
- property mask_shape
Return the shape of the masks.
- Returns:
Shape of the first mask in the dictionary.
- Return type:
tuple
- shift_polygons()[source]
Shift all polygon coordinates by (min_x, min_y).
- Return type:
None
Modifies#
- self.segmentationdict
Polygon coordinates are shifted in place.
- compute_overlap()[source]
Compute overlap between masks and segmented regions.
- Returns:
Nested dictionary of overlap counts {cell_id: {mask_name: pixel_overlap_count}}.
- Return type:
dict
- Raises:
NotImplementedError – If overlap for label masks is requested.
- map_mask_cell_masks()[source]
Placeholder for label mask-based overlap computation.
- Return type:
None
- map_mask_cell_polygons()[source]
Compute overlap counts between each segmentation polygon and each mask.
- Return type:
None
- Stores results in self.results as:
{cell_id: {mask_name: pixel_overlap_count, …}, …}
- plot_masks_overlay_segmentation(titles, colors, background='white', save_path=None, show=True, show_legend=True)[source]
Overlay binary masks and segmentation polygons for visualization.
- Parameters:
titles (list of str) – Titles for each mask.
colors (list of str) – Colors corresponding to each mask.
background (str, optional) – Background color, by default ‘white’.
save_path (str, optional) – Path to save the overlay plot, by default None.
show (bool, optional) – Whether to display the plot, by default True.
show_legend (bool, optional) – Whether to show legend, by default True.
- Return type:
None
- plot_colored_by_mask_overlap(mask_to_color, color_map='Reds', show=True, save_path=None, figsize=(15, 15))[source]
Color segmented polygons based on overlap percentage with specified masks.
- Parameters:
mask_to_color (list of str) – Mask names to base coloring on.
color_map (str, optional) – Matplotlib colormap, by default ‘Reds’.
show (bool, optional) – Whether to display the plot, by default True.
save_path (str, optional) – Path to save the plot, by default None.
figsize (tuple, optional) – Figure size, by default (15, 15).
- Return type:
None