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

skimage.measure.find_contours returns results outside masked areas #7300

Open
PierreRaybaut opened this issue Jan 18, 2024 · 1 comment
Open
Labels
🔰 Good first issue 📄 type: Documentation Updates, fixes and additions to documentation

Comments

@PierreRaybaut
Copy link

PierreRaybaut commented Jan 18, 2024

Description:

The skimage.measure.find_contours function sometimes returns contours which are entirely outside the input array masked areas, and thus that should be filtered out. This was reported in the context of DataLab (see the associated issue).

In DataLab, the "detection contour" feature is based on this function and, following a bug report, a workaround was added to simply filter out all contours which coordinates correspond to masked pixels:

    contours = measure.find_contours(data, level=get_absolute_level(data, level))
    coords = []
    for contour in contours:
        # `contour` is a (N, 2) array (rows, cols): we need to check if all those
        # coordinates are masked: if so, we skip this contour
        if isinstance(data, ma.MaskedArray) and np.all(
            data.mask[contour[:, 0].astype(int), contour[:, 1].astype(int)]
        ):
            continue

Way to reproduce:

The test image may be found here.

The test script which reproduced the issue (before it was fixed by adding the functions mentioned above) is here.

Please also take a look at the associated issue which describes the original problem.

Version information:

3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]
Windows-10-10.0.22631-SP0
scikit-image version: 0.22.0
numpy version: 1.26.1
@soupault
Copy link
Member

soupault commented Mar 21, 2024

Hello @PierreRaybaut and thank you for reporting!
Generally, scikit-image does not support masked arrays, so I would not consider this as a bug. In the context of this issue, however, it would be appropriate to clarify our stance in the documentation, e.g. https://scikit-image.org/docs/dev/user_guide/numpy_images.html .

@soupault soupault added 📄 type: Documentation Updates, fixes and additions to documentation 🔰 Good first issue and removed 🐛 Bug labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔰 Good first issue 📄 type: Documentation Updates, fixes and additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants