Skip to content

fix/test: DistanceTransform array out of bounds exception #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2025

Conversation

bogovicj
Copy link
Contributor

@bogovicj bogovicj commented Mar 6, 2025

bogovicj added 2 commits March 6, 2025 16:08
* both for distance and voronoiDistance transforms
* use primitive arrays rather than RealComposites
* get between 40% and 100% speedup
@bogovicj
Copy link
Contributor Author

bogovicj commented Mar 18, 2025

The second commit to this PR substantially speeds things up (40% - 100%) by using primitive arrays for parts of the lowest level methods transformAlongDimension and transformAlongDimensionPropagateLabels

Because this implementation makes an attempt to support very large images, we fall back to the old implementation if any dimension is longer than Integer.MAX_VALUE.

That commit also includes a benchmark, some of the results of which are shown below.

Note: there is certainly room for more optimization, but this covers some relatively low-hanging fruit.

Selected benchmark results

2D

old single thread

Benchmark                                            Mode  Cnt    Score   Error  Units
DistanceTransformBenchmark.distanceTransform  avgt   60  335.409 ± 2.358  ms/op
DistanceTransformBenchmark.voronoiDistanceTransform  avgt   25  484.629 ± 6.081  ms/op

new single thread

Benchmark                                            Mode  Cnt    Score   Error  Units
DistanceTransformBenchmark.distanceTransform  avgt   60  165.260 ± 1.427  ms/op
DistanceTransformBenchmark.voronoiDistanceTransform  avgt   25  295.930 ± 3.423  ms/op

old multi-thread (8)

Benchmark                                            Mode  Cnt    Score   Error  Units
DistanceTransformBenchmark.distanceTransform  avgt   25  106.692 ± 1.874  ms/op
DistanceTransformBenchmark.voronoiDistanceTransform  avgt   25  170.793 ± 1.800  ms/op

new multi-thread (8)

Benchmark                                            Mode  Cnt    Score   Error  Units
DistanceTransformBenchmark.distanceTransform  avgt   25  46.543 ± 1.638  ms/op
DistanceTransformBenchmark.voronoiDistanceTransform  avgt   25  118.340 ± 2.338  ms/op

3D

old single threaded

Benchmark                                            Mode  Cnt     Score    Error  Units
DistanceTransformBenchmark.distanceTransform         avgt   25  1167.336 ± 14.451  ms/op
DistanceTransformBenchmark.voronoiDistanceTransform  avgt   25  1852.702 ± 20.670  ms/op

new single threaded

Benchmark                                            Mode  Cnt     Score    Error  Units
DistanceTransformBenchmark.distanceTransform         avgt   25   605.162 ±  6.575  ms/op
DistanceTransformBenchmark.voronoiDistanceTransform  avgt   25  1315.934 ± 22.510  ms/op

@bogovicj bogovicj requested a review from axtimwalde March 18, 2025 19:49
@axtimwalde axtimwalde merged commit d5e11c4 into master Mar 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants