Skip to content

Commit fa49533

Browse files
Initial implementation and benchmarks for distance transform
1 parent 624d05a commit fa49533

11 files changed

Lines changed: 1288 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nanobind_add_module(_core
1313
NB_STATIC
1414
src/bindings/affinities.cxx
1515
src/bindings/blocking.cxx
16+
src/bindings/distance.cxx
1617
src/bindings/module.cxx
1718
src/bindings/filters.cxx
1819
src/bindings/graph.cxx

MIGRATION_GUIDE.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ Important differences from vigra and fastfilters:
15471547
largest → smallest. This matches `fastfilters`. To get vigra's
15481548
ascending order, reverse with `result[..., ::-1]`.
15491549
- No IIR / recursive Gaussian, no `convolve` / `recursiveFilter2D`, no
1550-
morphology, no distance transforms, no nonlinear diffusion, and no
1550+
morphology, no nonlinear diffusion, and no
15511551
non-local means in v1. Use `scipy.ndimage`, `skimage`, or the original
15521552
vigra/fastfilters bindings if you need those.
15531553

@@ -1562,6 +1562,48 @@ Implementation notes:
15621562
`detail/threading.hxx::parallel_for_chunks` without changing the
15631563
public API.
15641564

1565+
### Distance Transforms
1566+
1567+
`bioimage-cpp` exposes exact binary Euclidean distance transforms under
1568+
`bic.distance`.
1569+
1570+
SciPy / vigra:
1571+
1572+
```python
1573+
from scipy import ndimage
1574+
dist = ndimage.distance_transform_edt(mask, sampling=(2.0, 1.0))
1575+
1576+
import vigra.filters as vf
1577+
vec = vf.vectorDistanceTransform(mask)
1578+
```
1579+
1580+
bioimage-cpp:
1581+
1582+
```python
1583+
import bioimage_cpp as bic
1584+
1585+
dist = bic.distance.distance_transform(mask, sampling=(2.0, 1.0))
1586+
vec = bic.distance.vector_difference_transform(mask, sampling=(2.0, 1.0))
1587+
```
1588+
1589+
Name mapping:
1590+
1591+
| scipy / vigra name | bioimage-cpp name |
1592+
| --- | --- |
1593+
| `scipy.ndimage.distance_transform_edt` | `distance_transform` |
1594+
| `vigra.filters.vectorDistanceTransform` | `vector_difference_transform` |
1595+
1596+
Important differences:
1597+
1598+
- Distance-valued outputs are `float32`, not SciPy's `float64`.
1599+
- `distance_transform` follows SciPy's binary convention: nonzero values are
1600+
foreground and distances are measured to the nearest zero-valued element.
1601+
- `vector_difference_transform` returns `float32` vectors with shape
1602+
`mask.shape + (mask.ndim,)`. Components are sampled displacements from each
1603+
foreground element to its nearest zero-valued element in NumPy axis order.
1604+
- The initial implementation prioritizes correctness and API coverage over
1605+
performance; benchmarks and optimized kernels are planned separately.
1606+
15651607
## I/O and Build Dependencies
15661608

15671609
`bioimage-cpp` intentionally does not replace nifty or affogato I/O helpers.

0 commit comments

Comments
 (0)