zarrnii.plugins
Plugin API for segmentation and scaled-processing workflows, including hook markers, hook specifications, plugin-manager helpers, and bundled plugins.
Package exports
ZarrNii plugins package.
This package provides extensible plugin architectures for various image processing tasks such as segmentation, filtering, and analysis using the pluggy framework.
Plugin authors should depend on zarrnii and import hookimpl from
:mod:zarrnii.plugins.
Classes
zarrnii.plugins.GaussianBiasFieldCorrection(sigma=5.0, mode='reflect')
Bias field correction plugin using multi-resolution processing.
This plugin estimates a smooth bias field at low resolution using simple smoothing (as a placeholder for more sophisticated methods like N4) and applies the correction to full resolution data by division.
Parameters:
-
sigma(float, default:5.0) –Standard deviation for Gaussian smoothing (default: 5.0)
-
mode(str, default:'reflect') –Boundary condition for smoothing (default: 'reflect')
Initialize bias field correction plugin.
Parameters:
-
sigma(float, default:5.0) –Standard deviation for Gaussian smoothing
-
mode(str, default:'reflect') –Boundary condition for smoothing
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
29 30 31 32 33 34 35 36 37 38 | |
Functions
zarrnii.plugins.GaussianBiasFieldCorrection.lowres_func(lowres_array)
Estimate bias field from low-resolution data.
This is a simplified bias field estimation using Gaussian smoothing. In practice, this could be replaced with more sophisticated methods like N4 bias field correction.
Parameters:
-
lowres_array(ndarray) –Downsampled input image
Returns:
-
ndarray–Estimated bias field at low resolution
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
zarrnii.plugins.GaussianBiasFieldCorrection.highres_func(fullres_array, upsampled_output)
Apply bias field correction to full-resolution data.
This function takes the upsampled bias field (same size as fullres_array) and applies it to the full-resolution data by division.
Works with both dask arrays ("default" method) and plain NumPy arrays
("map_blocks" method) because only NumPy-compatible operations are used.
Parameters:
-
fullres_array–Full-resolution array (dask or NumPy)
-
upsampled_output–Upsampled bias field (same shape as fullres_array; dask or NumPy)
Returns:
-
–
Bias-corrected full-resolution array (same type as inputs)
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
zarrnii.plugins.GaussianBiasFieldCorrection.scaled_processing_plugin_name()
Return the name of the algorithm.
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
130 131 132 133 | |
zarrnii.plugins.GaussianBiasFieldCorrection.scaled_processing_plugin_description()
Return a description of the algorithm.
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
135 136 137 138 139 140 141 142 | |
zarrnii.plugins.N4BiasFieldCorrection(spline_param=[2, 2, 2], convergence={'iters': [50, 50, 50, 50], 'tol': 1e-07}, shrink_factor=1)
N4 bias field correction plugin using multi-resolution processing.
This plugin estimates a smooth bias field at low resolution using the N4 bias field correction algorithm from ANTsPy and applies the correction to full resolution data by division.
Parameters:
-
spline_param(tuple[int, int, int], default:[2, 2, 2]) –Spacing between knots for spline fitting (default: 200)
-
convergence(Optional[Dict[str, Any]], default:{'iters': [50, 50, 50, 50], 'tol': 1e-07}) –Convergence criteria [iters, tol] (default: [50, 0.001])
-
shrink_factor(int, default:1) –Shrink factor for processing (default: 1)
Initialize N4 bias field correction plugin.
Parameters:
-
spline_param(tuple[int, int, int], default:[2, 2, 2]) –Spacing between knots for spline fitting
-
convergence(Optional[Dict[str, Any]], default:{'iters': [50, 50, 50, 50], 'tol': 1e-07}) –Convergence criteria dict with 'iters' (list), 'tol'
-
shrink_factor(int, default:1) –Shrink factor for processing
Raises:
-
ImportError–If antspyx is not installed
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
Functions
zarrnii.plugins.N4BiasFieldCorrection.lowres_func(lowres_array)
Estimate bias field from low-resolution data using N4 algorithm.
This function uses ANTsPy's N4 bias field correction to estimate the bias field at low resolution.
Parameters:
-
lowres_array(ndarray) –Downsampled input image
Returns:
-
ndarray–Estimated bias field at low resolution
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
zarrnii.plugins.N4BiasFieldCorrection.highres_func(fullres_array, upsampled_output)
Apply bias field correction to full-resolution data.
This function takes the upsampled bias field (same size as fullres_array) and applies it to the full-resolution data by division.
Works with both dask arrays ("default" method) and plain NumPy arrays
("map_blocks" method) because only NumPy-compatible operations are used.
Parameters:
-
fullres_array–Full-resolution array (dask or NumPy)
-
upsampled_output–Upsampled bias field (same shape as fullres; dask or NumPy)
Returns:
-
–
Bias-corrected full-resolution array (same type as inputs)
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
zarrnii.plugins.N4BiasFieldCorrection.scaled_processing_plugin_name()
Return the name of the algorithm.
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
180 181 182 183 | |
zarrnii.plugins.N4BiasFieldCorrection.scaled_processing_plugin_description()
Return a description of the algorithm.
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
185 186 187 188 189 190 191 192 | |
zarrnii.plugins.SegmentationCleaner(mask_threshold=50, max_extent=0.15, exclusion_threshold=50)
Segmentation cleaning plugin using multi-resolution processing.
This plugin removes artifactual objects from segmentations by: 1. At low resolution: performing connected components analysis on a thresholded mask and identifying objects with extent below a threshold 2. At high resolution: applying an exclusion mask to remove these objects from the full-resolution segmentation
The extent of a region is defined as the ratio of pixels in the region to pixels in the total bounding box. Objects with low extent (e.g., < 0.15) are typically large artifactual objects with sparse coverage.
Parameters:
-
mask_threshold(float, default:50) –Threshold for creating initial binary mask (default: 50)
-
max_extent(float, default:0.15) –Maximum extent threshold for exclusion (default: 0.15)
-
exclusion_threshold(float, default:50) –Threshold for upsampled exclusion mask (default: 50)
Initialize segmentation cleaner plugin.
Parameters:
-
mask_threshold(float, default:50) –Threshold for creating initial binary mask from input
-
max_extent(float, default:0.15) –Maximum extent to include in exclusion mask (objects with extent < max_extent are considered artifactual)
-
exclusion_threshold(float, default:50) –Threshold for applying upsampled exclusion mask
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
Functions
zarrnii.plugins.SegmentationCleaner.lowres_func(lowres_array)
Create exclusion mask from low-resolution segmentation data.
This function performs connected components analysis on thresholded low-resolution data and creates an exclusion mask containing objects with extent below the threshold.
Parameters:
-
lowres_array(ndarray) –Downsampled segmentation image
Returns:
-
ndarray–Exclusion mask at low resolution (uint8, values 0 or 100)
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
zarrnii.plugins.SegmentationCleaner.highres_func(fullres_array, upsampled_output)
Apply exclusion mask to full-resolution segmentation data.
This function takes the upsampled exclusion mask and applies it to the full-resolution segmentation by zeroing out the excluded regions.
Works with both dask arrays ("default" method) and plain NumPy arrays
("map_blocks" method) because only NumPy-compatible operations are used.
Parameters:
-
fullres_array–Full-resolution segmentation array (dask or NumPy)
-
upsampled_output–Upsampled exclusion mask (same shape as fullres; dask or NumPy)
Returns:
-
–
Cleaned full-resolution segmentation array (same type as inputs)
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
zarrnii.plugins.SegmentationCleaner.scaled_processing_plugin_name()
Return the name of the algorithm.
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
153 154 155 156 | |
zarrnii.plugins.SegmentationCleaner.scaled_processing_plugin_description()
Return a description of the algorithm.
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
158 159 160 161 162 163 164 165 166 | |
zarrnii.plugins.LocalOtsuSegmentation(nbins=256)
Local Otsu thresholding segmentation plugin.
This plugin uses Otsu's method to automatically determine an optimal threshold for binary image segmentation. The method assumes a bimodal histogram and finds the threshold that minimizes intra-class variance. The threshold is computed locally for each processing block, making it suitable for images with varying illumination or contrast.
Parameters:
-
nbins(int, default:256) –Number of bins for histogram computation (default: 256)
Initialize local Otsu segmentation plugin.
Parameters:
-
nbins(int, default:256) –Number of bins for histogram computation
Source code in zarrnii/plugins/segmentation/local_otsu.py
32 33 34 35 36 37 38 39 | |
Functions
zarrnii.plugins.LocalOtsuSegmentation.segment(image, metadata=None)
Segment image using local Otsu thresholding.
Parameters:
-
image(ndarray) –Input image as numpy array
-
metadata(Optional[Dict[str, Any]], default:None) –Optional metadata (unused in Otsu method)
Returns:
-
ndarray–Binary segmentation mask as numpy array with same shape as input.
-
ndarray–Values are 0 (background) and 1 (foreground).
Raises:
-
ValueError–If input image is empty or has invalid dimensions
Source code in zarrnii/plugins/segmentation/local_otsu.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
zarrnii.plugins.LocalOtsuSegmentation.segmentation_plugin_name()
Return the name of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/local_otsu.py
109 110 111 112 | |
zarrnii.plugins.LocalOtsuSegmentation.segmentation_plugin_description()
Return a description of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/local_otsu.py
114 115 116 117 118 119 120 121 122 | |
zarrnii.plugins.LocalOtsuSegmentation.get_threshold(image)
Get the Otsu threshold value without applying segmentation.
Parameters:
-
image(ndarray) –Input image as numpy array
Returns:
-
float–Computed Otsu threshold value
Source code in zarrnii/plugins/segmentation/local_otsu.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
zarrnii.plugins.ThresholdSegmentation(thresholds, inclusive=True)
Threshold-based segmentation plugin.
This plugin applies threshold-based segmentation using either a single threshold value or multiple threshold values to create labeled regions. It can use manually specified thresholds or thresholds computed from analysis functions like Otsu multi-thresholding.
Parameters:
-
thresholds(Union[float, List[float]]) –Single threshold value or list of threshold values. For single threshold, creates binary segmentation (0/1). For multiple thresholds, creates multi-class segmentation (0/1/2/...).
-
inclusive(bool, default:True) –Whether thresholds are inclusive (default: True). If True, pixels >= threshold are labeled as foreground. If False, pixels > threshold are labeled as foreground.
Initialize threshold segmentation plugin.
Parameters:
-
thresholds(Union[float, List[float]]) –Single threshold or list of thresholds
-
inclusive(bool, default:True) –Whether thresholds are inclusive (>= vs >)
Source code in zarrnii/plugins/segmentation/threshold.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
Functions
zarrnii.plugins.ThresholdSegmentation.segment(image, metadata=None)
Segment image using threshold values.
Parameters:
-
image(ndarray) –Input image as numpy array
-
metadata(Optional[Dict[str, Any]], default:None) –Optional metadata (unused in threshold method)
Returns:
-
ndarray–Labeled segmentation mask as numpy array with same shape as input.
-
ndarray–Values are 0 (background), 1, 2, ... up to len(thresholds) classes.
Raises:
-
ValueError–If input image is empty
Source code in zarrnii/plugins/segmentation/threshold.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
zarrnii.plugins.ThresholdSegmentation.segmentation_plugin_name()
Return the name of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/threshold.py
89 90 91 92 93 94 95 | |
zarrnii.plugins.ThresholdSegmentation.segmentation_plugin_description()
Return a description of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/threshold.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
zarrnii.plugins.ThresholdSegmentation.get_thresholds()
Get the threshold values used by this plugin.
Returns:
-
List[float]–List of threshold values
Source code in zarrnii/plugins/segmentation/threshold.py
118 119 120 121 122 123 124 125 | |
Functions
zarrnii.plugins.get_global_plugin_manager()
Get the global plugin manager instance.
Returns:
-
PluginManager–Global PluginManager instance
Source code in zarrnii/plugins/plugin_manager.py
34 35 36 37 38 39 40 41 42 43 44 | |
zarrnii.plugins.get_plugin_manager()
Get or create the ZarrNii plugin manager.
Returns:
-
PluginManager–PluginManager instance configured for ZarrNii plugins
Source code in zarrnii/plugins/plugin_manager.py
15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Hook specifications
Plugin hook specifications for ZarrNii plugins.
This module defines the hook specifications that plugins must implement.
Classes
zarrnii.plugins.hookspecs.ZarrNiiSpec
Hook specifications for ZarrNii plugins.
Plugin authors should implement any subset of these hooks as plain methods
decorated with @hookimpl from :mod:zarrnii.plugins.
Example::
from zarrnii.plugins import hookimpl
class MyPlugin:
@hookimpl
def segment(self, image, metadata=None):
...
Functions
zarrnii.plugins.hookspecs.ZarrNiiSpec.segment(image, metadata=None)
Segment an image and return a binary or labeled mask.
Parameters:
-
image–Input image as numpy array.
-
metadata–Optional metadata dictionary containing image information.
Returns:
-
–
Segmented image as numpy array.
Source code in zarrnii/plugins/hookspecs.py
28 29 30 31 32 33 34 35 36 37 38 | |
zarrnii.plugins.hookspecs.ZarrNiiSpec.segmentation_plugin_name()
Return the name of the segmentation algorithm.
Returns:
-
str–String name of the algorithm.
Source code in zarrnii/plugins/hookspecs.py
40 41 42 43 44 45 46 | |
zarrnii.plugins.hookspecs.ZarrNiiSpec.segmentation_plugin_description()
Return a description of the segmentation algorithm.
Returns:
-
str–String description of the algorithm.
Source code in zarrnii/plugins/hookspecs.py
48 49 50 51 52 53 54 | |
zarrnii.plugins.hookspecs.ZarrNiiSpec.scaled_processing_plugin_name()
Return the name of the scaled processing algorithm.
Returns:
-
str–String name of the algorithm.
Source code in zarrnii/plugins/hookspecs.py
56 57 58 59 60 61 62 | |
zarrnii.plugins.hookspecs.ZarrNiiSpec.scaled_processing_plugin_description()
Return a description of the scaled processing algorithm.
Returns:
-
str–String description of the algorithm.
Source code in zarrnii/plugins/hookspecs.py
64 65 66 67 68 69 70 | |
zarrnii.plugins.hookspecs.ZarrNiiSpec.lowres_func(lowres_array)
Process low-resolution data and return the result.
This function operates on a downsampled numpy array and computes the algorithm output that will be upsampled and applied to the full-resolution data.
Parameters:
-
lowres_array–Downsampled input image as numpy array.
Returns:
-
–
Low-resolution output array (e.g., bias field, correction map).
Source code in zarrnii/plugins/hookspecs.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
zarrnii.plugins.hookspecs.ZarrNiiSpec.highres_func(fullres_array, upsampled_output)
Apply upsampled output to full-resolution data blockwise.
Parameters:
-
fullres_array–Full-resolution dask array.
-
upsampled_output–Upsampled output (same shape as fullres_array).
Returns:
-
–
Processed full-resolution dask array.
Source code in zarrnii/plugins/hookspecs.py
87 88 89 90 91 92 93 94 95 96 97 | |
Plugin manager
Plugin manager for ZarrNii plugins.
This module provides the plugin manager that discovers and manages plugins using the pluggy framework.
Classes
Functions
zarrnii.plugins.plugin_manager.get_plugin_manager()
Get or create the ZarrNii plugin manager.
Returns:
-
PluginManager–PluginManager instance configured for ZarrNii plugins
Source code in zarrnii/plugins/plugin_manager.py
15 16 17 18 19 20 21 22 23 24 25 26 27 | |
zarrnii.plugins.plugin_manager.get_global_plugin_manager()
Get the global plugin manager instance.
Returns:
-
PluginManager–Global PluginManager instance
Source code in zarrnii/plugins/plugin_manager.py
34 35 36 37 38 39 40 41 42 43 44 | |
Built-in segmentation plugins
Local Otsu thresholding segmentation plugin.
This module implements Otsu's automatic threshold selection method for binary image segmentation, applied locally to each processing block.
Classes
zarrnii.plugins.segmentation.local_otsu.LocalOtsuSegmentation(nbins=256)
Local Otsu thresholding segmentation plugin.
This plugin uses Otsu's method to automatically determine an optimal threshold for binary image segmentation. The method assumes a bimodal histogram and finds the threshold that minimizes intra-class variance. The threshold is computed locally for each processing block, making it suitable for images with varying illumination or contrast.
Parameters:
-
nbins(int, default:256) –Number of bins for histogram computation (default: 256)
Initialize local Otsu segmentation plugin.
Parameters:
-
nbins(int, default:256) –Number of bins for histogram computation
Source code in zarrnii/plugins/segmentation/local_otsu.py
32 33 34 35 36 37 38 39 | |
Functions
zarrnii.plugins.segmentation.local_otsu.LocalOtsuSegmentation.segment(image, metadata=None)
Segment image using local Otsu thresholding.
Parameters:
-
image(ndarray) –Input image as numpy array
-
metadata(Optional[Dict[str, Any]], default:None) –Optional metadata (unused in Otsu method)
Returns:
-
ndarray–Binary segmentation mask as numpy array with same shape as input.
-
ndarray–Values are 0 (background) and 1 (foreground).
Raises:
-
ValueError–If input image is empty or has invalid dimensions
Source code in zarrnii/plugins/segmentation/local_otsu.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
zarrnii.plugins.segmentation.local_otsu.LocalOtsuSegmentation.segmentation_plugin_name()
Return the name of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/local_otsu.py
109 110 111 112 | |
zarrnii.plugins.segmentation.local_otsu.LocalOtsuSegmentation.segmentation_plugin_description()
Return a description of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/local_otsu.py
114 115 116 117 118 119 120 121 122 | |
zarrnii.plugins.segmentation.local_otsu.LocalOtsuSegmentation.get_threshold(image)
Get the Otsu threshold value without applying segmentation.
Parameters:
-
image(ndarray) –Input image as numpy array
Returns:
-
float–Computed Otsu threshold value
Source code in zarrnii/plugins/segmentation/local_otsu.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Threshold segmentation plugin.
This module implements threshold-based segmentation that can use either manual threshold values or computed thresholds (e.g., from Otsu analysis).
Classes
zarrnii.plugins.segmentation.threshold.ThresholdSegmentation(thresholds, inclusive=True)
Threshold-based segmentation plugin.
This plugin applies threshold-based segmentation using either a single threshold value or multiple threshold values to create labeled regions. It can use manually specified thresholds or thresholds computed from analysis functions like Otsu multi-thresholding.
Parameters:
-
thresholds(Union[float, List[float]]) –Single threshold value or list of threshold values. For single threshold, creates binary segmentation (0/1). For multiple thresholds, creates multi-class segmentation (0/1/2/...).
-
inclusive(bool, default:True) –Whether thresholds are inclusive (default: True). If True, pixels >= threshold are labeled as foreground. If False, pixels > threshold are labeled as foreground.
Initialize threshold segmentation plugin.
Parameters:
-
thresholds(Union[float, List[float]]) –Single threshold or list of thresholds
-
inclusive(bool, default:True) –Whether thresholds are inclusive (>= vs >)
Source code in zarrnii/plugins/segmentation/threshold.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
Functions
zarrnii.plugins.segmentation.threshold.ThresholdSegmentation.segment(image, metadata=None)
Segment image using threshold values.
Parameters:
-
image(ndarray) –Input image as numpy array
-
metadata(Optional[Dict[str, Any]], default:None) –Optional metadata (unused in threshold method)
Returns:
-
ndarray–Labeled segmentation mask as numpy array with same shape as input.
-
ndarray–Values are 0 (background), 1, 2, ... up to len(thresholds) classes.
Raises:
-
ValueError–If input image is empty
Source code in zarrnii/plugins/segmentation/threshold.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
zarrnii.plugins.segmentation.threshold.ThresholdSegmentation.segmentation_plugin_name()
Return the name of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/threshold.py
89 90 91 92 93 94 95 | |
zarrnii.plugins.segmentation.threshold.ThresholdSegmentation.segmentation_plugin_description()
Return a description of the segmentation algorithm.
Source code in zarrnii/plugins/segmentation/threshold.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
zarrnii.plugins.segmentation.threshold.ThresholdSegmentation.get_thresholds()
Get the threshold values used by this plugin.
Returns:
-
List[float]–List of threshold values
Source code in zarrnii/plugins/segmentation/threshold.py
118 119 120 121 122 123 124 125 | |
Built-in scaled-processing plugins
Gaussian Bias field correction plugin using multi-resolution processing.
This module implements a bias field correction plugin that estimates the bias field at low resolution and applies it to full resolution data.
Classes
zarrnii.plugins.scaled_processing.gaussian_biasfield.GaussianBiasFieldCorrection(sigma=5.0, mode='reflect')
Bias field correction plugin using multi-resolution processing.
This plugin estimates a smooth bias field at low resolution using simple smoothing (as a placeholder for more sophisticated methods like N4) and applies the correction to full resolution data by division.
Parameters:
-
sigma(float, default:5.0) –Standard deviation for Gaussian smoothing (default: 5.0)
-
mode(str, default:'reflect') –Boundary condition for smoothing (default: 'reflect')
Initialize bias field correction plugin.
Parameters:
-
sigma(float, default:5.0) –Standard deviation for Gaussian smoothing
-
mode(str, default:'reflect') –Boundary condition for smoothing
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
29 30 31 32 33 34 35 36 37 38 | |
Functions
zarrnii.plugins.scaled_processing.gaussian_biasfield.GaussianBiasFieldCorrection.lowres_func(lowres_array)
Estimate bias field from low-resolution data.
This is a simplified bias field estimation using Gaussian smoothing. In practice, this could be replaced with more sophisticated methods like N4 bias field correction.
Parameters:
-
lowres_array(ndarray) –Downsampled input image
Returns:
-
ndarray–Estimated bias field at low resolution
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
zarrnii.plugins.scaled_processing.gaussian_biasfield.GaussianBiasFieldCorrection.highres_func(fullres_array, upsampled_output)
Apply bias field correction to full-resolution data.
This function takes the upsampled bias field (same size as fullres_array) and applies it to the full-resolution data by division.
Works with both dask arrays ("default" method) and plain NumPy arrays
("map_blocks" method) because only NumPy-compatible operations are used.
Parameters:
-
fullres_array–Full-resolution array (dask or NumPy)
-
upsampled_output–Upsampled bias field (same shape as fullres_array; dask or NumPy)
Returns:
-
–
Bias-corrected full-resolution array (same type as inputs)
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
zarrnii.plugins.scaled_processing.gaussian_biasfield.GaussianBiasFieldCorrection.scaled_processing_plugin_name()
Return the name of the algorithm.
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
130 131 132 133 | |
zarrnii.plugins.scaled_processing.gaussian_biasfield.GaussianBiasFieldCorrection.scaled_processing_plugin_description()
Return a description of the algorithm.
Source code in zarrnii/plugins/scaled_processing/gaussian_biasfield.py
135 136 137 138 139 140 141 142 | |
N4 Bias field correction plugin using multi-resolution processing.
This module implements a bias field correction plugin that estimates the bias field at low resolution using N4 algorithm from ANTsPy and applies it to full resolution data.
Classes
zarrnii.plugins.scaled_processing.n4_biasfield.N4BiasFieldCorrection(spline_param=[2, 2, 2], convergence={'iters': [50, 50, 50, 50], 'tol': 1e-07}, shrink_factor=1)
N4 bias field correction plugin using multi-resolution processing.
This plugin estimates a smooth bias field at low resolution using the N4 bias field correction algorithm from ANTsPy and applies the correction to full resolution data by division.
Parameters:
-
spline_param(tuple[int, int, int], default:[2, 2, 2]) –Spacing between knots for spline fitting (default: 200)
-
convergence(Optional[Dict[str, Any]], default:{'iters': [50, 50, 50, 50], 'tol': 1e-07}) –Convergence criteria [iters, tol] (default: [50, 0.001])
-
shrink_factor(int, default:1) –Shrink factor for processing (default: 1)
Initialize N4 bias field correction plugin.
Parameters:
-
spline_param(tuple[int, int, int], default:[2, 2, 2]) –Spacing between knots for spline fitting
-
convergence(Optional[Dict[str, Any]], default:{'iters': [50, 50, 50, 50], 'tol': 1e-07}) –Convergence criteria dict with 'iters' (list), 'tol'
-
shrink_factor(int, default:1) –Shrink factor for processing
Raises:
-
ImportError–If antspyx is not installed
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
Functions
zarrnii.plugins.scaled_processing.n4_biasfield.N4BiasFieldCorrection.lowres_func(lowres_array)
Estimate bias field from low-resolution data using N4 algorithm.
This function uses ANTsPy's N4 bias field correction to estimate the bias field at low resolution.
Parameters:
-
lowres_array(ndarray) –Downsampled input image
Returns:
-
ndarray–Estimated bias field at low resolution
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
zarrnii.plugins.scaled_processing.n4_biasfield.N4BiasFieldCorrection.highres_func(fullres_array, upsampled_output)
Apply bias field correction to full-resolution data.
This function takes the upsampled bias field (same size as fullres_array) and applies it to the full-resolution data by division.
Works with both dask arrays ("default" method) and plain NumPy arrays
("map_blocks" method) because only NumPy-compatible operations are used.
Parameters:
-
fullres_array–Full-resolution array (dask or NumPy)
-
upsampled_output–Upsampled bias field (same shape as fullres; dask or NumPy)
Returns:
-
–
Bias-corrected full-resolution array (same type as inputs)
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
zarrnii.plugins.scaled_processing.n4_biasfield.N4BiasFieldCorrection.scaled_processing_plugin_name()
Return the name of the algorithm.
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
180 181 182 183 | |
zarrnii.plugins.scaled_processing.n4_biasfield.N4BiasFieldCorrection.scaled_processing_plugin_description()
Return a description of the algorithm.
Source code in zarrnii/plugins/scaled_processing/n4_biasfield.py
185 186 187 188 189 190 191 192 | |
Segmentation cleaning plugin using multi-resolution processing.
This module implements a segmentation cleaning plugin that removes artifactual objects from a segmentation by performing connected components analysis at low resolution and filtering by extent, then applying the exclusion mask to full resolution data.
Classes
zarrnii.plugins.scaled_processing.segmentation_cleaner.SegmentationCleaner(mask_threshold=50, max_extent=0.15, exclusion_threshold=50)
Segmentation cleaning plugin using multi-resolution processing.
This plugin removes artifactual objects from segmentations by: 1. At low resolution: performing connected components analysis on a thresholded mask and identifying objects with extent below a threshold 2. At high resolution: applying an exclusion mask to remove these objects from the full-resolution segmentation
The extent of a region is defined as the ratio of pixels in the region to pixels in the total bounding box. Objects with low extent (e.g., < 0.15) are typically large artifactual objects with sparse coverage.
Parameters:
-
mask_threshold(float, default:50) –Threshold for creating initial binary mask (default: 50)
-
max_extent(float, default:0.15) –Maximum extent threshold for exclusion (default: 0.15)
-
exclusion_threshold(float, default:50) –Threshold for upsampled exclusion mask (default: 50)
Initialize segmentation cleaner plugin.
Parameters:
-
mask_threshold(float, default:50) –Threshold for creating initial binary mask from input
-
max_extent(float, default:0.15) –Maximum extent to include in exclusion mask (objects with extent < max_extent are considered artifactual)
-
exclusion_threshold(float, default:50) –Threshold for applying upsampled exclusion mask
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
Functions
zarrnii.plugins.scaled_processing.segmentation_cleaner.SegmentationCleaner.lowres_func(lowres_array)
Create exclusion mask from low-resolution segmentation data.
This function performs connected components analysis on thresholded low-resolution data and creates an exclusion mask containing objects with extent below the threshold.
Parameters:
-
lowres_array(ndarray) –Downsampled segmentation image
Returns:
-
ndarray–Exclusion mask at low resolution (uint8, values 0 or 100)
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
zarrnii.plugins.scaled_processing.segmentation_cleaner.SegmentationCleaner.highres_func(fullres_array, upsampled_output)
Apply exclusion mask to full-resolution segmentation data.
This function takes the upsampled exclusion mask and applies it to the full-resolution segmentation by zeroing out the excluded regions.
Works with both dask arrays ("default" method) and plain NumPy arrays
("map_blocks" method) because only NumPy-compatible operations are used.
Parameters:
-
fullres_array–Full-resolution segmentation array (dask or NumPy)
-
upsampled_output–Upsampled exclusion mask (same shape as fullres; dask or NumPy)
Returns:
-
–
Cleaned full-resolution segmentation array (same type as inputs)
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
zarrnii.plugins.scaled_processing.segmentation_cleaner.SegmentationCleaner.scaled_processing_plugin_name()
Return the name of the algorithm.
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
153 154 155 156 | |
zarrnii.plugins.scaled_processing.segmentation_cleaner.SegmentationCleaner.scaled_processing_plugin_description()
Return a description of the algorithm.
Source code in zarrnii/plugins/scaled_processing/segmentation_cleaner.py
158 159 160 161 162 163 164 165 166 | |