Skip to content
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

[BUG] distance_transform_edt gives bad output for 2D images > 1024 in size on either axis #392

Closed
grlee77 opened this issue Aug 22, 2022 · 0 comments · Fixed by #393
Closed
Labels
bug Something isn't working

Comments

@grlee77
Copy link
Contributor

grlee77 commented Aug 22, 2022

Describe the bug
There is currently a bug in the 2D implementation of distance_transform_edt where certain lines of the output have incorrect values due to a bad default choice of internal CUDA grid/block parameters at this size. Fortunately, the 3D distance transform does not suffer from the same issue.

A temporary workaround in release 22.08.00 is to manually specify the block_params argument and set the first parameter to 1. This is smaller than needed for optimal performance, but will ensure a correct result.

In general for 2D images where one axis is larger than 1024, please set block_params=(1, 32, 2). Other than as a workaround for this bug or in case of advanced performance profiling use cases, we recommend leaveling block_params=None to allow internal choice of these kernel launch parameters.

Steps/Code to reproduce bug
a minimal example

import math
import cupy as cp

import matplotlib.pyplot as plt

from cucim.core.operations.morphology import distance_transform_edt

shape = (1200, 1200)
size = math.prod(shape)
ntrue = .0005* size
p_true =  ntrue / size
p_false = 1 - p_true

cp.random.seed(123)
image = cp.random.choice([0, 1], size=shape, p=(p_false, p_true))

distances, coords = distance_transform_edt(
    image == 0, return_distances=True, return_indices=True
)
plt.figure()
plt.imshow(distances.get(), vmin=0, vmax=116)
plt.show()

gives this distances output where the bright horizontal lines are invalid distances
edt_bad

whereas calling with

distances, coords = distance_transform_edt(
    image == 0, return_distances=True, return_indices=True, block_params(1, 32, 2)
)

gives the correct result:
edt_good

Expected behavior
no artifacts with the default choice of block_params

Environment details (please complete the following information):
cuCIM v22.08.,00

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant