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

grayreconstruct.reconstruction incorrect when footprint offset is specified #7315

Open
dchaley opened this issue Feb 8, 2024 · 0 comments
Open
Labels

Comments

@dchaley
Copy link

dchaley commented Feb 8, 2024

Description:

Hi! I think I found a bug in the skimage.morphology.grayreconstruct.reconstruction function. [src]

The unit test test_offset_not_none [src] asserts that the seed:

    seed = np.array([0, 3, 6, 2, 1, 1, 1, 4, 2, 0])

and the mask:

    mask = np.array([0, 8, 6, 8, 8, 8, 8, 4, 4, 0])

with footprint [1, 1, 1] and offset [0], reconstruct as:

    expected = np.array([0, 3, 6, 6, 6, 6, 6, 4, 4, 0])

But I think it should be:

[0 6 6 4 4 4 4 4 2 0]

I explain my reasoning in this document.

I include 2 approaches:

  1. Manual application of parallel iterative algorithm
  2. Comparison to a simple OpenCV-based implementation (repro included)

For some context, I am hoping to submit a PR that rewrites the algorithm more efficiently.
Along the way I found that our algorithms disagreed, which brought me here.
I'm not sure how to fix the offset case in the current code, it seems like it may be reversing the footprint but I am not sure.
If you are curious you can see my work-in-progress implementation here.

Thank you– happy to provide any additional information!

Way to reproduce:

import numpy as np
import skimage.morphology.grayreconstruct


seed = np.array([0, 3, 6, 2, 1, 1, 1, 4, 2, 0])
mask = np.array([0, 8, 6, 8, 8, 8, 8, 4, 4, 0])

skimage_result = skimage.morphology.grayreconstruct.reconstruction(
   seed,
   mask,
   method="dilation",
   footprint=np.array([1, 1, 1], dtype=np.uint8),
   offset=np.array([0], dtype=np.uint8),
)


print(skimage_result)


# Output: [0. 3. 6. 6. 6. 6. 6. 4. 4. 0.]

Version information:

In [1]: import sys; print(sys.version)
   ...: import platform; print(platform.platform())
   ...: import skimage; print(f'scikit-image version: {skimage.__version__}')
   ...: import numpy; print(f'numpy version: {numpy.__version__}')
3.10.13 (main, Aug 24 2023, 22:48:59) [Clang 14.0.3 (clang-1403.0.22.14.1)]
macOS-14.2.1-x86_64-i386-64bit
scikit-image version: 0.19.3
numpy version: 1.23.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant