Hi,

I often do this with ds9 and funtools.
ds9 is an astronomy-oriented image viewer (http://hea-www.harvard.edu/RD/ds9/)
but you can also use it with numpy array.
Within ds9, you can define regions (ellipse, polynomial, etc) easily
with a mouse.
After you define a region (and save it as a file), you can convert it
to a mask image
with funtools (funtools is a name of an astronomy-oriented image
utility pacakge).
funtools only support fits file (image format in astronomy) so this
can be a bit tricky, but if you're
interested i'll send my python wrapper code for it.

So, take a look at ds9 and see it fits your need.
To view numpy array in ds9,
  *. From python, save the array as a file (tofile method, better use
"arr" as an extension)
  * in ds9, file-> open others -> open array. You need to select
array dimension, type and  endianness of the array.

Regards,

-JJ





On Sat, Mar 8, 2008 at 11:17 AM, Chiara Caronna
<[EMAIL PROTECTED]> wrote:
>
>  Hello,
> I am also interested in masking polygons and defining the polygon by
> 'clicking' on the image... but I do not know anything about GUI.... does
> anyone can help? Is there already something implemented?
> Thanks!
> Chiara
>
> > Date: Wed, 23 Jan 2008 13:50:15 +1300
> > From: [EMAIL PROTECTED]
> > To: matplotlib-users@lists.sourceforge.net
> > Subject: Re: [Matplotlib-users] Polygon masking possible?
>
>
> >
> > Hi Søren,
> >
> > I've put this back on the list in case it's useful to anyone else, or
> > if there are better suggestions or improvements around. Hope you don't
> > mind.
> >
> > On 22/01/2008, Søren Nielsen <[EMAIL PROTECTED]> wrote:
> > > Yeah i'd like to see your code if I can..
> >
> > import numpy as n
> >
> > def get_poly_pts(x, y, shape):
> > """Creates convex polygon mask from list of corners.
> >
> > Parameters
> > ----------
> > x : array_like
> > x co-ordinates of corners
> > y : array_like
> > y co-ordinates of corners, in order corresponding to x
> > shape : array_like
> > dimension sizes of result
> >
> > Returns
> > -------
> > build : ndarray
> > 2-D array of shape shape with values True inside polygon
> >
> > Notes
> > -----
> > Code is constrained to convex polygons by "inside"
> > assessment criterion.
> >
> > """
> > x = n.asarray(x)
> > y = n.asarray(y)
> > shape = n.asarray(shape)
> > npts = x.size # should probably assert x.size == y.size
> > inds = n.indices( shape )
> > xs = inds[0]
> > ys = inds[1]
> > xav = n.round(x.mean()).astype(int)
> > yav = n.round(y.mean()).astype(int)
> > for i in xrange(npts): # iterate over pairs of co-ordinates
> > j = (i + 1) % npts
> > m = (y[j] - y[i])/(x[j] - x[i])
> > c = (x[j] * y[i] - x[i] * y[j])/(x[j] - x[i])
> > thisone = ( ys > m * xs + c )
> > if thisone[xav, yav] == False:
> > thisone = ~thisone
> > if i == 0:
> > build = thisone
> > else:
> > build &= thisone
> > return build
> >
> > (released under BSD licence)
> >
> > > I just needed the push over the edge to know how to draw on the canvas,
> > > mapping clicks etc. since i'm still fairly new to matplotlib, so I think
> > > your code will be helpfull.
> >
> > I hope so. As you can see this code doesn't do any of the drawing or
> > click collecting, but the cookbook page should be able to guide you
> > there. Ask again on the list if you have any further questions and
> > we'll see if we can help.
> >
> > Also, the code assumes that the average co-ordinate is inside the
> > shape - that's true for convex polygons, but not necessarily for
> > arbitrary ones. I use if after taking a convex hull of a greater list
> > of points (using the delaunay module in scipy (now in scikits, I
> > hear)), which ensures convexity. You just need to be aware of that
> > limitation.
> >
> > Cheers,
> >
> > A.
> > --
> > AJC McMorland, PhD candidate
> > Physiology, University of Auckland
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> ________________________________
> Express yourself instantly with MSN Messenger! MSN Messenger
> -------------------------------------------------------------------------
>  This SF.net email is sponsored by: Microsoft
>  Defy all challenges. Microsoft(R) Visual Studio 2008.
>  http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
>  Matplotlib-users mailing list
>  Matplotlib-users@lists.sourceforge.net
>  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to