Skip to content

Consider adding mask support for SLIC #1569

Closed

Description

@ahoyosid

I would like to know if is possible to perform the SLIC segmentation on a masked array, it means to give the mask as a parameter to the method.

This is important when you want to segment within a region of interest.

Thank you in advance

Activity

  1. jni commented on Jun 27, 2015

    @jni
    Member

    Hi @ahoyosid! This is not currently supported. It might be a good addition.

    If we do add it, it would probably be through a "mask" keyword argument, as in watershed, because we generally prefer the convention of considering pixels marked as True, whereas masked arrays use True to denote "hidden" pixels.

    In the meantime, the easiest workaround would be to pass the bounding box around your ROI. I realise this will not be ideal in the case of irregularly-shaped ROIs, but it might get you some of the way there.

  2. changed the title [-]SLIC + masked data[/-] [+]Consider adding mask support for SLIC[/+] on Jun 27, 2015
  3. jni commented on Jun 27, 2015

    @jni
    Member

    @ahoyosid I've changed the title of the issue to help us keep track of this as a feature request.

  4. ahoyosid commented on Jun 30, 2015

    @ahoyosid
    Author

    Thank you @jni, that is the approach I been using, but the shape of my signal is quite irregular.

    Hope this will be implemented in future releases, in the mean time I will continue with the workaround

  5. added
    ⏩ type: Enhancement
    on Dec 11, 2015
  6. benjaminirving commented on Jul 1, 2016

    @benjaminirving

    Hi,

    I've had a go at modifying the SLIC method with a mask for my own purposes. I decided to reinitialise the seed points because initialising on a grid is not optimal for an irregular mask.

    Here's my modification:
    https://github.com/benjaminirving/maskSLIC

    If something like this is of interest to scikit-image then I can redo this as a pull request.

  7. jni commented on Jul 1, 2016

    @jni
    Member

    @benjaminirving very cool! I like the seed laying algorithm. =)

    My concern right now is that you still iterate over the whole image. I think it should be possible to instead convert the mask to a list of z, y, x indices and iterate over those... What do you think?

    In general though we are very happy to work with you to get this included into scikit-image!

  8. benjaminirving commented on Jul 1, 2016

    @benjaminirving

    @jni, great. Thanks for your input. When I get a chance I will redo as a pull request and we can take it from there.

    I agree it would be more efficient as a list of indices. In this initial version, I've tried to keep it as close to the original code as possible. I guess it depends on whether this should be added as a separate _mslic_cython function or just as a mask parameter in the existing function.

    If we want to keep it in the same function, then an alternative option would just be to loop over a bounding box around the mask, which will keep the code very similar but improve the efficiency.

  9. kwiechen commented on Sep 19, 2016

    @kwiechen

    @benjaminirving thank you very much for your efforts! I started with maskslic to get a meaningful oversegmentation of histology images masking the background. Using this with enforce_connectivity=True results in

    File "maskslic_slic.pyx", line 218, in maskslic._slic._enforce_label_connectivity_cython (maskslic/_slic.c:4125)
    ValueError: Buffer dtype mismatch, expected 'Py_ssize_t' but got 'long'

    Unfortunately I have no experience with Cython to remove this error

    Best regards,

    Kai

  10. benjaminirving commented on Sep 19, 2016

    @benjaminirving

    @kwiechen. Thanks for picking this up. This code is still a bit of a work in progress and I've been delayed wrapping it up.

    I will need to rework the enforce_connectivity method. I hadn't used it previously.

    I've updated the README.md file to highlight the current issues with the code and will hopefully get a chance to look into it this week.

    Thanks again,

    Ben

  11. benjaminirving commented on Sep 23, 2016

    @benjaminirving

    @kwiechen, I think I've fixed the issue. See some enforce connectivity examples that I've added to run_example.py. Would you mind testing it and letting me know if it works for you?

    https://github.com/benjaminirving/maskSLIC

    Ben

  12. kwiechen commented on Sep 25, 2016

    @kwiechen

    @benjaminirving, I've tested with some histology slides and it works nicely. However seed_type='nplace', recompute_seeds=True is computationally very expensive.

    Best regards,

    Kai
    figure_1

  13. benjaminirving commented on Sep 27, 2016

    @benjaminirving

    Awesome. Works nicely on that image.

    Yip. I've been using it for smaller regions so I imagine that the way it places the seed points could be slow. I'm going to work on optimising various parts of it.

    Feel free to add this and any other issues directly to the maskslic github project: https://github.com/benjaminirving/maskSLIC and I'll try and resolve them when I get a chance.

  14. benjaminirving commented on Sep 27, 2016

    @benjaminirving

    @kwiechen, Btw, for such a large image it probably doesn't matter if you use nplace

    Set:
    seed_type='grid'
    recompute_seed=True

    In this case it should give you a much quicker result. 'nplace' is most useful for small regions or large superpixels.

  15. kwiechen commented on Oct 3, 2016

    @kwiechen

    @benjaminirving,

    seed_type='grid', recompute_seed=True approx. doubles runtime, with 'nplace' the runtime is more than 10-fold higher.

    There are weird results without warning if there is a non-bool mask parameter (for me uint8 after resizing the mask).

    Best regards,

    Kai

  16. benjaminirving commented on Dec 4, 2016

    @benjaminirving

    Thanks @kwiechen . I've moved this issue to my code where it will be easier to deal with.

  17. d-diaz commented on Jul 3, 2018

    @d-diaz

    Chiming in (late, it seems) that a mask argument would be a helpful addition to SLIC. I am working with segmenting satellite imagery within property and/or watershed boundaries, which commonly have non-rectangular shapes. Using a mask would be a very nice option to avoid generating a lot of superpixels for areas outside the region of interest.

  18. jni commented on Jul 5, 2018

    @jni
    Member

    @d-diaz this would make a lovely addition! Unfortunately we are completely swamped at the moment. I don't see any of the core devs driving this in the near future. If you submit it as a PR, though, we would certainly work with you to get it merged. It looks like @benjaminirving already has a BSD-licensed version here:

    https://github.com/benjaminirving/maskSLIC

    so hopefully it is just a matter of merging that code with ours and submitting the PR...!

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ⏩ type: Enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions