Plotting boundaries of segmented data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Plotting boundaries of segmented data

rwleo
Hello,

I am trying to plot a 2-D array with segmentation data from a fluid flow. The data structure is continuous which means that the segments are connected regions, like in the picture below:

I use
plt.imshow(seg, cmap="Greys")
which returns a black area on a white background. What I would like to achieve instead is to plot only the boundary as a black curve, like when plotting a shape with pylab setting edgecolor=black and facecolor=white. Unfortunately, having the data in matrix format I am not sure whether this can easily be achieved without writing a separate function that detects whether a pixel belongs to the border or the interior. Is there an alternative to the imshow function which does this simply by setting some keywords?

Secondly I would like to smoothen the boundary curve which looks quite "rectangular" due to the coarse segmentation algorithm that has been applied to the fluid flow data. Can this be done with interp2d, if the segments are not based on an analytical expression?

Many thanks in advance!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting boundaries of segmented data

tcaswell
Please subscribe to the mailing list so you can post un-moderated (https://mail.python.org/mailman/listinfo/matplotlib-users )

I think you are looking for the contour family of methods, see http://matplotlib.org/examples/pylab_examples/contour_demo.html 

Tom

On Sat, Jan 28, 2017 at 10:58 AM rwleo <[hidden email]> wrote:
Hello,

I am trying to plot a 2-D array with segmentation data from a fluid flow.
The data structure is continuous which means that the segments are connected
regions, like in the picture below:
<http://matplotlib.1069221.n5.nabble.com/file/n47655/figure.png>
I use
plt.imshow(seg, cmap="Greys")
which returns a black area on a white background. What I would like to
achieve instead is to plot only the boundary as a black curve, like when
plotting a shape with pylab setting edgecolor=black and facecolor=white.
Unfortunately, having the data in matrix format I am not sure whether this
can easily be achieved without writing a separate function that detects
whether a pixel belongs to the border or the interior. Is there an
alternative to the imshow function which does this simply by setting some
keywords?

Secondly I would like to smoothen the boundary curve which looks quite
"rectangular" due to the coarse segmentation algorithm that has been applied
to the fluid flow data. Can this be done with interp2d, if the segments are
not based on an analytical expression?

Many thanks in advance!



--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-boundaries-of-segmented-data-tp47655.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting boundaries of segmented data

tcaswell
You might also be interested in http://scikit-image.org/docs/dev/auto_examples/edges/plot_contours.html which may be more efficient at finding the edge.

Tom 

On Sat, Jan 28, 2017 at 2:36 PM Peter Leitner <[hidden email]> wrote:

Indeed, plotting a single contour of binary data is an option I have not considered yet. Thank you for the suggestion! For the time being I solved the issue by looping through the arrays marking only boundary cells and displaying the boundary as a scatter plot which worked quite well, but I will revisit your suggestion to effortlessly display the boundary as a contour. Many thanks again!

Peter


On 01/28/2017 05:45 PM, Thomas Caswell wrote:
Please subscribe to the mailing list so you can post un-moderated (https://mail.python.org/mailman/listinfo/matplotlib-users )

I think you are looking for the contour family of methods, see http://matplotlib.org/examples/pylab_examples/contour_demo.html 

Tom

On Sat, Jan 28, 2017 at 10:58 AM rwleo <[hidden email]> wrote:
Hello,

I am trying to plot a 2-D array with segmentation data from a fluid flow.
The data structure is continuous which means that the segments are connected
regions, like in the picture below:
<http://matplotlib.1069221.n5.nabble.com/file/n47655/figure.png>
I use
plt.imshow(seg, cmap="Greys")
which returns a black area on a white background. What I would like to
achieve instead is to plot only the boundary as a black curve, like when
plotting a shape with pylab setting edgecolor=black and facecolor=white.
Unfortunately, having the data in matrix format I am not sure whether this
can easily be achieved without writing a separate function that detects
whether a pixel belongs to the border or the interior. Is there an
alternative to the imshow function which does this simply by setting some
keywords?

Secondly I would like to smoothen the boundary curve which looks quite
"rectangular" due to the coarse segmentation algorithm that has been applied
to the fluid flow data. Can this be done with interp2d, if the segments are
not based on an analytical expression?

Many thanks in advance!



--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-boundaries-of-segmented-data-tp47655.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

-- 
Dr. Peter Leitner
Institute of Physics, University of Graz
Universitätsplatz 5, 8010 Graz Austria

Mobile: +43-316-699-17-115-726
Skype: live:p.leitner_7
Mail: [hidden email]

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting boundaries of segmented data

rwleo
This post has NOT been accepted by the mailing list yet.

I haven't heard of that package before! This might indeed be an option to more closely aligning the contours to the boundaries especially at edges be them concave or convex. And it's easy to apply in addition. Thank you, you just saved me hours of internet search and possibly further programming efforts! I am glad to see that others have already implemented such solutions.

Best wishes,
Peter


On 01/28/2017 08:39 PM, tcaswell [via matplotlib] wrote:
You might also be interested in http://scikit-image.org/docs/dev/auto_examples/edges/plot_contours.html which may be more efficient at finding the edge.

Tom 

On Sat, Jan 28, 2017 at 2:36 PM Peter Leitner <[hidden email]> wrote:

Indeed, plotting a single contour of binary data is an option I have not considered yet. Thank you for the suggestion! For the time being I solved the issue by looping through the arrays marking only boundary cells and displaying the boundary as a scatter plot which worked quite well, but I will revisit your suggestion to effortlessly display the boundary as a contour. Many thanks again!

Peter


On 01/28/2017 05:45 PM, Thomas Caswell wrote:
Please subscribe to the mailing list so you can post un-moderated (https://mail.python.org/mailman/listinfo/matplotlib-users )

I think you are looking for the contour family of methods, see http://matplotlib.org/examples/pylab_examples/contour_demo.html 

Tom

On Sat, Jan 28, 2017 at 10:58 AM rwleo <[hidden email]> wrote:
Hello,

I am trying to plot a 2-D array with segmentation data from a fluid flow.
The data structure is continuous which means that the segments are connected
regions, like in the picture below:
<http://matplotlib.1069221.n5.nabble.com/file/n47655/figure.png>
I use
plt.imshow(seg, cmap="Greys")
which returns a black area on a white background. What I would like to
achieve instead is to plot only the boundary as a black curve, like when
plotting a shape with pylab setting edgecolor=black and facecolor=white.
Unfortunately, having the data in matrix format I am not sure whether this
can easily be achieved without writing a separate function that detects
whether a pixel belongs to the border or the interior. Is there an
alternative to the imshow function which does this simply by setting some
keywords?

Secondly I would like to smoothen the boundary curve which looks quite
"rectangular" due to the coarse segmentation algorithm that has been applied
to the fluid flow data. Can this be done with interp2d, if the segments are
not based on an analytical expression?

Many thanks in advance!



--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-boundaries-of-segmented-data-tp47655.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

-- 
Dr. Peter Leitner
Institute of Physics, University of Graz
Universitätsplatz 5, 8010 Graz Austria

Mobile: +43-316-699-17-115-726
Skype: live:p.leitner_7
Mail: [hidden email]

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



If you reply to this email, your message will be added to the discussion below:
http://matplotlib.1069221.n5.nabble.com/Plotting-boundaries-of-segmented-data-tp47655p47819.html
To unsubscribe from Plotting boundaries of segmented data, click here.
NAML

-- 
Dr. Peter Leitner
Institute of Physics, University of Graz
Universitätsplatz 5, 8010 Graz Austria

Mobile: +43-316-699-17-115-726
Skype: live:p.leitner_7
Mail: [hidden email]
Loading...