## [Matplotlib-users] Contouring

 [Matplotlib-users] Contouring From: - 2007-11-30 12:47:41 ```Hi, I have written a quick'n'dirty image segmentation algorithm. It seems to work fine. However, I am interested in getting contours of the segments (essentially, (x,y) pairs of the edges of each segment). I can plot the contours with MPL (pylab.contour()), but I'd like to have the locations of the edges, so that I can actually do something with them. Does anyone have any hints on how to go on about this? Thanks! Jose ```

 [Matplotlib-users] Contouring From: - 2007-11-30 12:47:41 ```Hi, I have written a quick'n'dirty image segmentation algorithm. It seems to work fine. However, I am interested in getting contours of the segments (essentially, (x,y) pairs of the edges of each segment). I can plot the contours with MPL (pylab.contour()), but I'd like to have the locations of the edges, so that I can actually do something with them. Does anyone have any hints on how to go on about this? Thanks! Jose ```
 Re: [Matplotlib-users] Contouring From: Eric Firing - 2007-11-30 18:29:35 ```José Gómez-Dans wrote: > Hi, > I have written a quick'n'dirty image segmentation algorithm. It seems to work > fine. However, I am interested in getting contours of the segments > (essentially, (x,y) pairs of the edges of each segment). I can plot the > contours with MPL (pylab.contour()), but I'd like to have the locations of > the edges, so that I can actually do something with them. > > Does anyone have any hints on how to go on about this? cs = contour(Z) for lev, col in zip(cs.levels, cs.collections): s = col._segments s will be a list of numpy arrays, each containing the (x,y) vertices defining a contour line at level lev. This illustrates a shortcoming of the contour and/or LineCollection code; to get what I think you want, you have to use a private attribute, _segments. It should be part of the public API. After some other changes and reorganizations in mpl have settled down, I will fix this. Feel free to send me a reminder in a month. Eric ```