Pixel-boundary contours for segmentation visualisation

Hi, I'm struggling with a problem that I'm sure has been solved before - and probably by some users of this mailing list! I have a segmentation image and I want to extract the edges of the segments and show them on the original image. This sounds nice and easy, so I had a go using the matplotlib contour function and got the following: <https://lh3.googleusercontent.com/-S2zawy2Wsq0/Vi3i9tFMwbI/AAAAAAADLj0/2Gt22...>
From my perspective, there are two issues with this: one is that the two segments (which are separate by pixels with the value zero) are actually joined, and the other is that the segment outlines don't follow the pixel boundaries: they are offset by around half a pixel, and 'cut the corners'. What I'd really like to produce is the following:
<https://lh3.googleusercontent.com/-UUwZAEhue8I/Vi3jQewKW-I/AAAAAAADLj8/gh66G...> (if you look carefully you can see the blue outline around the edge of the segment) Does anyone know how to do this easily (and, ideally, reasonably quickly) in Python? From my investigations it seems that the contour function won't do what I want - but I can't find anything else that will do this, and I'd rather not implement something from scratch. Any thoughts? Robin

Hi Robin! Well, the easy workaround is to zoom your image a lot using ndi.zoom or skimage.transform.rescale, and then use mpl's contour. =) The potentially slower way is to use scikit-image.segmentation.mark_boundary with mode=subpixel. =) Juan. On Mon, Oct 26, 2015 at 7:25 PM, Robin Wilson <r.t.wilson.bak@googlemail.com> wrote:
Hi, I'm struggling with a problem that I'm sure has been solved before - and probably by some users of this mailing list! I have a segmentation image and I want to extract the edges of the segments and show them on the original image. This sounds nice and easy, so I had a go using the matplotlib contour function and got the following: <https://lh3.googleusercontent.com/-S2zawy2Wsq0/Vi3i9tFMwbI/AAAAAAADLj0/2Gt22...> From my perspective, there are two issues with this: one is that the two segments (which are separate by pixels with the value zero) are actually joined, and the other is that the segment outlines don't follow the pixel boundaries: they are offset by around half a pixel, and 'cut the corners'. What I'd really like to produce is the following: <https://lh3.googleusercontent.com/-UUwZAEhue8I/Vi3jQewKW-I/AAAAAAADLj8/gh66G...> (if you look carefully you can see the blue outline around the edge of the segment) Does anyone know how to do this easily (and, ideally, reasonably quickly) in Python? From my investigations it seems that the contour function won't do what I want - but I can't find anything else that will do this, and I'd rather not implement something from scratch. Any thoughts? Robin -- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.

Thanks for the quick reply Juan. I'm going to be picky now...! I've tried the mark_boundary approach, but I hadn't realised that it produced raster boundaries, so they look rather blurry in the output image: <https://lh3.googleusercontent.com/-1zRUm9D32Nk/Vi3q3oI5cBI/AAAAAAADLkM/wR6Xu...> I imagine I could probably use the information from find_boundaries to produce lists of vector points that I could then plot with matplotlib - to get a nice vector overlay. Before I implement that, has anyone done that already? Thanks, Robin On Monday, 26 October 2015 08:33:31 UTC, Juan Nunez-Iglesias wrote:
Hi Robin!
Well, the easy workaround is to zoom your image a lot using ndi.zoom or skimage.transform.rescale, and then use mpl's contour. =)
The potentially slower way is to use scikit-image.segmentation.mark_boundary with mode=subpixel. =)
Juan.
On Mon, Oct 26, 2015 at 7:25 PM, Robin Wilson <r.t.wil...@googlemail.com <javascript:>> wrote:
Hi,
I'm struggling with a problem that I'm sure has been solved before - and probably by some users of this mailing list! I have a segmentation image and I want to extract the edges of the segments and show them on the original image. This sounds nice and easy, so I had a go using the matplotlib contour function and got the following:
<https://lh3.googleusercontent.com/-S2zawy2Wsq0/Vi3i9tFMwbI/AAAAAAADLj0/2Gt22...>
From my perspective, there are two issues with this: one is that the two segments (which are separate by pixels with the value zero) are actually joined, and the other is that the segment outlines don't follow the pixel boundaries: they are offset by around half a pixel, and 'cut the corners'. What I'd really like to produce is the following:
<https://lh3.googleusercontent.com/-UUwZAEhue8I/Vi3jQewKW-I/AAAAAAADLj8/gh66G...>
(if you look carefully you can see the blue outline around the edge of the segment)
Does anyone know how to do this easily (and, ideally, reasonably quickly) in Python? From my investigations it seems that the contour function won't do what I want - but I can't find anything else that will do this, and I'd rather not implement something from scratch.
Any thoughts?
Robin
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com <javascript:>. For more options, visit https://groups.google.com/d/optout.

Erm, maybe try interpolation='nearest' with imshow... =) Not sure about the other approach, though you are right that it would be possible. On Mon, Oct 26, 2015 at 8:02 PM, Robin Wilson <r.t.wilson.bak@googlemail.com> wrote:
Thanks for the quick reply Juan. I'm going to be picky now...! I've tried the mark_boundary approach, but I hadn't realised that it produced raster boundaries, so they look rather blurry in the output image: <https://lh3.googleusercontent.com/-1zRUm9D32Nk/Vi3q3oI5cBI/AAAAAAADLkM/wR6Xu...> I imagine I could probably use the information from find_boundaries to produce lists of vector points that I could then plot with matplotlib - to get a nice vector overlay. Before I implement that, has anyone done that already? Thanks, Robin On Monday, 26 October 2015 08:33:31 UTC, Juan Nunez-Iglesias wrote:
Hi Robin!
Well, the easy workaround is to zoom your image a lot using ndi.zoom or skimage.transform.rescale, and then use mpl's contour. =)
The potentially slower way is to use scikit-image.segmentation.mark_boundary with mode=subpixel. =)
Juan.
On Mon, Oct 26, 2015 at 7:25 PM, Robin Wilson <r.t.wil...@googlemail.com <javascript:>> wrote:
Hi,
I'm struggling with a problem that I'm sure has been solved before - and probably by some users of this mailing list! I have a segmentation image and I want to extract the edges of the segments and show them on the original image. This sounds nice and easy, so I had a go using the matplotlib contour function and got the following:
<https://lh3.googleusercontent.com/-S2zawy2Wsq0/Vi3i9tFMwbI/AAAAAAADLj0/2Gt22...>
From my perspective, there are two issues with this: one is that the two segments (which are separate by pixels with the value zero) are actually joined, and the other is that the segment outlines don't follow the pixel boundaries: they are offset by around half a pixel, and 'cut the corners'. What I'd really like to produce is the following:
<https://lh3.googleusercontent.com/-UUwZAEhue8I/Vi3jQewKW-I/AAAAAAADLj8/gh66G...>
(if you look carefully you can see the blue outline around the edge of the segment)
Does anyone know how to do this easily (and, ideally, reasonably quickly) in Python? From my investigations it seems that the contour function won't do what I want - but I can't find anything else that will do this, and I'd rather not implement something from scratch.
Any thoughts?
Robin
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com <javascript:>. For more options, visit https://groups.google.com/d/optout.
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.

Oh duh! Of course, setting the interpolation properly makes it look far more sensible! I might still investigate the vector approach - I'll post here if I succeed. Robin On Monday, 26 October 2015 09:22:47 UTC, Juan Nunez-Iglesias wrote:
Erm, maybe try interpolation='nearest' with imshow... =)
Not sure about the other approach, though you are right that it would be possible.
On Mon, Oct 26, 2015 at 8:02 PM, Robin Wilson <r.t.wil...@googlemail.com <javascript:>> wrote:
Thanks for the quick reply Juan.
I'm going to be picky now...!
I've tried the mark_boundary approach, but I hadn't realised that it produced raster boundaries, so they look rather blurry in the output image:
<https://lh3.googleusercontent.com/-1zRUm9D32Nk/Vi3q3oI5cBI/AAAAAAADLkM/wR6Xu...>
I imagine I could probably use the information from find_boundaries to produce lists of vector points that I could then plot with matplotlib - to get a nice vector overlay. Before I implement that, has anyone done that already?
Thanks,
Robin
On Monday, 26 October 2015 08:33:31 UTC, Juan Nunez-Iglesias wrote:
Hi Robin!
Well, the easy workaround is to zoom your image a lot using ndi.zoom or skimage.transform.rescale, and then use mpl's contour. =)
The potentially slower way is to use scikit-image.segmentation.mark_boundary with mode=subpixel. =)
Juan.
On Mon, Oct 26, 2015 at 7:25 PM, Robin Wilson <r.t.wil...@googlemail.com
wrote:
Hi,
I'm struggling with a problem that I'm sure has been solved before - and probably by some users of this mailing list! I have a segmentation image and I want to extract the edges of the segments and show them on the original image. This sounds nice and easy, so I had a go using the matplotlib contour function and got the following:
<https://lh3.googleusercontent.com/-S2zawy2Wsq0/Vi3i9tFMwbI/AAAAAAADLj0/2Gt22...>
From my perspective, there are two issues with this: one is that the two segments (which are separate by pixels with the value zero) are actually joined, and the other is that the segment outlines don't follow the pixel boundaries: they are offset by around half a pixel, and 'cut the corners'. What I'd really like to produce is the following:
<https://lh3.googleusercontent.com/-UUwZAEhue8I/Vi3jQewKW-I/AAAAAAADLj8/gh66G...>
(if you look carefully you can see the blue outline around the edge of the segment)
Does anyone know how to do this easily (and, ideally, reasonably quickly) in Python? From my investigations it seems that the contour function won't do what I want - but I can't find anything else that will do this, and I'd rather not implement something from scratch.
Any thoughts?
Robin
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com <javascript:>. For more options, visit https://groups.google.com/d/optout.
participants (2)
-
Juan Nunez-Iglesias
-
Robin Wilson