Seam report
patchworks.seam_report(labels: Union[str, Path, 'zarr.Array'], tile_shape: Sequence[int], *, component: str = '0', min_voxels: int = 4, max_faces: int = 64, warn_ratio: float = 2.0) -> dict[str, Any]
Measure whether tile seams leave artifacts in a merged label image.
For every axis, compares the orphan rate at tile seams -- the fraction
of labels touching one side of a seam with nothing continuing on the
other -- against the same rate on control planes halfway through each
tile. A seam rate well above the interior rate means the tiling shows:
raise overlap (it should cover about one object), or try
stitch="iou".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
(str, Path or Array)
|
The merged labels: a zarr array, or a group path plus component
(default |
required |
tile_shape
|
sequence of int
|
The tile shape the segmentation ran with. |
required |
component
|
str
|
Array inside labels when it is a path. |
'0'
|
min_voxels
|
int
|
Ignore labels with fewer voxels than this on the slice (edge grazes). |
4
|
max_faces
|
int
|
Cap on seam faces (and as many control faces) read per axis, spread evenly over the image (default 64). Each face is a two-voxel slab of one tile's cross-section, so this bounds the I/O on a huge store: 64 z-faces of a 1024 x 1024 int32 tile read ~1 GB. |
64
|
warn_ratio
|
float
|
Log a warning when an axis' seam rate exceeds its interior rate by this factor. |
2.0
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Examples:
>>> seam_report("scan.zarr/labels/cells", (16, 1024, 1024))
{'axes': {0: {'seam_rate': 0.11, 'interior_rate': 0.10, ...}, ...}, ...}
Source code in src/patchworks/_seams.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 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 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 | |
Choosing the overlap
patchworks.suggest_overlap(image: Union[da.Array, np.ndarray], fn: Callable[[np.ndarray], np.ndarray], tile_shape: Sequence[int], *, candidates: Sequence[int] = (0, 4, 8, 16, 32, 64), region: 'tuple[slice, ...] | None' = None, crop_tiles: int = 2, target: float = 0.99, stitch: str = 'touch') -> dict[str, Any]
Smallest overlap whose tiled result matches an untiled one.
Segments a crop spanning crop_tiles tiles per axis once without
tiling, then with tile_process at each candidate overlap, scoring
each by :func:object_f1 against the untiled reference. Candidates are
tried in increasing order and the search stops at the first that reaches
target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
dask or NumPy array
|
The image as |
required |
fn
|
callable
|
The segmentation function. It is run on the crop in one piece, so the
crop must fit it ( |
required |
tile_shape
|
sequence of int
|
The tile shape the real run will use. |
required |
candidates
|
sequence of int
|
Overlaps to try, in voxels (applied on every axis the tile allows). |
(0, 4, 8, 16, 32, 64)
|
region
|
tuple of slice
|
The crop to use; default a centred block of tiles. Pick one with typical objects -- an empty crop agrees at any overlap. |
None
|
crop_tiles
|
int
|
Tiles per axis in the default crop (default 2). |
2
|
target
|
float
|
F1 counted as "tiling makes no difference" (default 0.99). |
0.99
|
stitch
|
str
|
Stitching mode of the real run ( |
'touch'
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Examples:
>>> from patchworks import suggest_overlap
>>> suggest_overlap(img, fn, (16, 512, 512))["overlap"]
16
Source code in src/patchworks/_autotune.py
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 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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
patchworks.object_f1(a: np.ndarray, b: np.ndarray, iou: float = 0.5) -> float
Object-level F1 between two label images at an IoU threshold.
Two objects match when their IoU exceeds iou (above 0.5 a match is necessarily one-to-one). 1.0 means every object in one has its counterpart in the other; background-only images agree perfectly.