You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
@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!
@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.
@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
@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?
@benjaminirving, I've tested with some histology slides and it works nicely. However seed_type='nplace', recompute_seeds=True is computationally very expensive.
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.
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.
@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:
Activity
jni commentedon Jun 27, 2015
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 asTrue, whereas masked arrays useTrueto 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.
[-]SLIC + masked data[/-][+]Consider adding mask support for SLIC[/+]jni commentedon Jun 27, 2015
@ahoyosid I've changed the title of the issue to help us keep track of this as a feature request.
ahoyosid commentedon Jun 30, 2015
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
benjaminirving commentedon Jul 1, 2016
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.
jni commentedon Jul 1, 2016
@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!
benjaminirving commentedon Jul 1, 2016
@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_cythonfunction or just as amaskparameter 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.
kwiechen commentedon Sep 19, 2016
@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
benjaminirving commentedon Sep 19, 2016
@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
benjaminirving commentedon Sep 23, 2016
@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
kwiechen commentedon Sep 25, 2016
@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

benjaminirving commentedon Sep 27, 2016
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.
benjaminirving commentedon Sep 27, 2016
@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.
kwiechen commentedon Oct 3, 2016
@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
benjaminirving commentedon Dec 4, 2016
Thanks @kwiechen . I've moved this issue to my code where it will be easier to deal with.
d-diaz commentedon Jul 3, 2018
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.
jni commentedon Jul 5, 2018
@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!