Volume filtering
patchworks.filter_labels_by_size(store_path: str, component: str, min_voxels: 'int | None' = None, max_voxels: 'int | None' = None, *, relabel: bool = True) -> 'tuple[int, int]'
Drop label objects outside [min_voxels, max_voxels], in place.
Two-pass streaming scan (see module docstring) -- the array never has to fit in RAM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_path
|
str
|
Path to the zarr store containing the label array. |
required |
component
|
str
|
Array name inside the store to filter in place. |
required |
min_voxels
|
int
|
Objects with fewer voxels than this are zeroed (dropped). |
None
|
max_voxels
|
int
|
Objects with more voxels than this are zeroed (dropped) -- e.g. a
segmentation artifact where several objects merged into one giant
blob. |
None
|
relabel
|
bool
|
Renumber the surviving objects to a contiguous |
True
|
Returns:
| Type | Description |
|---|---|
tuple of int
|
|
Examples:
>>> import zarr
>>> root = zarr.open_group("labels.zarr", mode="w")
>>> root.create_array(
... "labels", shape=(4, 4), chunks=(4, 4), dtype="int32"
... )[:] = [
... [0, 1, 1, 0],
... [0, 1, 1, 0],
... [0, 0, 0, 2],
... [0, 0, 0, 0],
... ]
>>> filter_labels_by_size("labels.zarr", "labels", min_voxels=2)
(1, 1)
Source code in src/patchworks/_volume_filter.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
patchworks.voxel_volume(voxel_size: 'dict[str, float]') -> float
Physical volume of one voxel, from a per-axis calibration.
Axes missing from voxel_size are treated as 1.0 -- e.g. a 2-D
calibration with no z gives an area, not a bogus volume shrunk by a
fake axis. Units follow whatever voxel_size is in (micrometers for
:func:patchworks.plugins.ome_zarr.read_pixel_size).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_size
|
dict
|
Per-axis physical size, e.g. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Product of the given axis sizes. |
Examples:
Source code in src/patchworks/_volume_filter.py
patchworks.min_voxels_for_volume(min_volume: float, voxel_size: 'dict[str, float]') -> int
Convert a physical volume threshold to a voxel count.
Rounds up: an object must reach min_volume to survive, so a partial voxel's worth of extra volume should not tip it over the line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_volume
|
float
|
Minimum object volume to keep, in the same physical units as voxel_size (micrometers³ for an NGFF calibration). |
required |
voxel_size
|
dict
|
Per-axis physical size -- see :func: |
required |
Returns:
| Type | Description |
|---|---|
int
|
Minimum voxel count for an object to survive filtering. |
Examples:
Source code in src/patchworks/_volume_filter.py
patchworks.max_voxels_for_volume(max_volume: float, voxel_size: 'dict[str, float]') -> int
Convert a physical volume threshold to a voxel count.
Rounds down, the mirror image of :func:min_voxels_for_volume: an
object must not exceed max_volume, so a voxel count whose volume
would tip past it must not survive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_volume
|
float
|
Maximum object volume to keep, in the same physical units as voxel_size (micrometers³ for an NGFF calibration). |
required |
voxel_size
|
dict
|
Per-axis physical size -- see :func: |
required |
Returns:
| Type | Description |
|---|---|
int
|
Maximum voxel count for an object to survive filtering. |
Examples: