[Matplotlib-users] Polygon masking possible?
Hi, I'm looking for a way to do masking of an Image.. I need to be able to make a circle / box or a user made polygon on an image using the mouse and retrieve the pixellocations of all pixels inside the masked area.. (which will then be processed later) Has anyone tried this? What is the easiest way to start? I'm using wxpython for the GUI. Thanks! Soren Nielsen - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Polygon masking possible?
On 22/01/2008, Søren Nielsen <[EMAIL PROTECTED]> wrote: > I'm looking for a way to do masking of an Image.. I need to be able to make > a circle / box or a user made polygon on an image using the mouse and > retrieve the pixellocations of all pixels inside the masked area.. (which > will then be processed later) I have very recently written some code that creates a binary mask (2-D array) of an irregular polygon given the co-ordinates of the corners. It successively uses equations of the line segments between pairs of neighbouring points around the polygon edge and sets the pixels on the inner side of those lines. I doubt it's the most efficient code, but seem so to work, and I'm happy to send you a copy it if it might be helpful. > Has anyone tried this? What is the easiest way > to start? I'm using wxpython for the GUI. It's relatively easy to capture successive mouse clicks using mpl, and use those co-ordinates for the polygon calculating code. An example of capturing mouse co-ordinates is in the cookbook: http://www.scipy.org/Cookbook/Matplotlib/Interactive_Plotting. Best regards, Angus. -- 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/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] build matplotlib including backend wxPython
Hello list, I was not up to date with my installation and I tried to use the latest svn version (trunk) on my Debian etch. I have a problem to build matplotlib including support for wxPython as backend. The output is attached below. Actually I cannot find a file "wxPython.h" on my system. Can anybody give me a hint what I'm doing wrong? How can I find wx headers and tell their location matplotlib? best regards and thanks in advance for any hint, Matthias $ python setup.py build BUILDING MATPLOTLIB matplotlib: 0.98pre python: 2.4.4 (#2, Apr 5 2007, 20:11:18) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] platform: linux2 REQUIRED DEPENDENCIES numpy: 1.0.4 freetype2: 9.10.3 OPTIONAL BACKEND DEPENDENCIES libpng: 1.2.15beta5 Tkinter: Tkinter: 39220, Tk: 8.4, Tcl: 8.4 wxPython: 2.6.3.2 * Could not find wxPython headers in any of * '/usr/lib/wx/include/gtk2-unicode-release-2.6', * '/usr/include/wx-2.6' Gtk+: gtk+: 2.8.20, glib: 2.12.4, pygtk: 2.8.6, pygobject: [pre-pygobject] Qt: Qt: 3.3.6, PyQt: 3.16 Qt4: no Cairo: 1.2.0 OPTIONAL DATE/TIMEZONE DEPENDENCIES datetime: present, version unknown dateutil: present, version unknown pytz: 2006p OPTIONAL USETEX DEPENDENCIES dvipng: 1.9 ghostscript: 8.15.3 latex: 3.141592 pdftops: 3.01 EXPERIMENTAL CONFIG PACKAGE DEPENDENCIES configobj: matplotlib will provide enthought.traits: matplotlib will provide [Edit setup.cfg to suppress the above messages] running build running build_py copying lib/matplotlib/mpl-data/matplotlibrc -> build/lib.linux-i686-2.4/matplotlib/mpl-data copying lib/matplotlib/mpl-data/matplotlib.conf -> build/lib.linux-i686-2.4/matplotlib/mpl-data running build_ext building 'matplotlib.backends._wxagg' extension C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes -fPIC compile options: '-DGTK_NO_CHECK_CASTS -D__WXGTK__ -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_LARGEFILE_SOURCE=1 -DNO_GCC_PRAGMA -I/usr/include/libpng12 -I/usr/local/include -I/usr/include -I. -I/var/lib/python-support/python2.4/numpy/core/include -Isrc -Iagg24/include -I. -I/usr/include/freetype2 -I/usr/local/include -I/usr/include -I. -I/usr/lib/wx/include/gtk2-unicode-release-2.6 -I/usr/include/wx-2.6 -I/usr/include/python2.4 -c' gcc: src/_wxagg.cpp cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ In file included from /usr/include/python2.4/Python.h:8, from ./CXX/WrapPython.h:47, from ./CXX/Extensions.hxx:48, from src/_backend_agg.h:8, from src/_wxagg.cpp:48: /usr/include/python2.4/pyconfig.h:851:1: warning: "_POSIX_C_SOURCE" redefined In file included from /usr/include/string.h:26, from /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring:52, from src/_wxagg.cpp:38: /usr/include/features.h:150:1: warning: this is the location of the previous definition src/_wxagg.cpp:55:34: error: wx/wxPython/wxPython.h: No such file or directory src/_wxagg.cpp: In member function 'Py::Object _wxagg_module::convert_agg_to_wx_image(const Py::Tuple&)': src/_wxagg.cpp:103: error: 'wxPyConstructObject' was not declared in this scope src/_wxagg.cpp: In member function 'Py::Object _wxagg_module::convert_agg_to_wx_bitmap(const Py::Tuple&)': src/_wxagg.cpp:125: error: 'wxPyConstructObject' was not declared in this scope src/_wxagg.cpp: In function 'void init_wxagg()': src/_wxagg.cpp:253: error: 'wxPyCoreAPI_IMPORT' was not declared in this scope /var/lib/python-support/python2.4/numpy/core/include/numpy/__multiarray_api.h: At global scope: /var/lib/python-support/python2.4/numpy/core/include/numpy/__multiarray_api.h:943: warning: 'int _import_array()' defined but not used cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ In file included from /usr/include/python2.4/Python.h:8, from ./CXX/WrapPython.h:47, from ./CXX/Extensions.hxx:48, from src/_backend_agg.h:8, from src/_wxagg.cpp:48: /usr/include/python2.4/pyconfig.h:851:1: warning: "_POSIX_C_SOURCE" redefined In file included from /usr/include/string.h:26, from /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring:52, from src/_wxagg.cpp:38: /usr/include/features.h:1
Re: [Matplotlib-users] build matplotlib including backend wxPython
This is a known bug in the Debian packaging of wxPython. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=326440 There are some workarounds mentioned in that post. Personally, I usually end up building wxPython from source (which doesn't have this header file problem) to keep up with its fairly frequent bugfixes anyway. If you'd prefer to stick with deb packages, you could *try* the wxPython-provided .deb packages (i.e. not the Debian-provided ones) here, though I don't know whether they also exhibit this problem: http://wiki.wxpython.org/InstallingOnUbuntuOrDebian Cheers, Mike Matthias Michler wrote: > Hello list, > > I was not up to date with my installation and I tried to use the latest svn > version (trunk) on my Debian etch. I have a problem to build matplotlib > including support for wxPython as backend. The output is attached below. > > Actually I cannot find a file "wxPython.h" on my system. > > Can anybody give me a hint what I'm doing wrong? > How can I find wx headers and tell their location matplotlib? > > best regards and thanks in advance for any hint, > Matthias > > > > $ python setup.py build > > BUILDING MATPLOTLIB > matplotlib: 0.98pre > python: 2.4.4 (#2, Apr 5 2007, 20:11:18) [GCC 4.1.2 > 20061115 (prerelease) (Debian 4.1.1-21)] > platform: linux2 > > REQUIRED DEPENDENCIES > numpy: 1.0.4 > freetype2: 9.10.3 > > OPTIONAL BACKEND DEPENDENCIES > libpng: 1.2.15beta5 >Tkinter: Tkinter: 39220, Tk: 8.4, Tcl: 8.4 > wxPython: 2.6.3.2 > * Could not find wxPython headers in any of > * '/usr/lib/wx/include/gtk2-unicode-release-2.6', > * '/usr/include/wx-2.6' > Gtk+: gtk+: 2.8.20, glib: 2.12.4, pygtk: 2.8.6, pygobject: > [pre-pygobject] > Qt: Qt: 3.3.6, PyQt: 3.16 >Qt4: no > Cairo: 1.2.0 > > OPTIONAL DATE/TIMEZONE DEPENDENCIES > datetime: present, version unknown > dateutil: present, version unknown > pytz: 2006p > > OPTIONAL USETEX DEPENDENCIES > dvipng: 1.9 >ghostscript: 8.15.3 > latex: 3.141592 >pdftops: 3.01 > > EXPERIMENTAL CONFIG PACKAGE DEPENDENCIES > configobj: matplotlib will provide > enthought.traits: matplotlib will provide > > [Edit setup.cfg to suppress the above messages] > > running build > running build_py > copying lib/matplotlib/mpl-data/matplotlibrc -> > build/lib.linux-i686-2.4/matplotlib/mpl-data > copying lib/matplotlib/mpl-data/matplotlib.conf -> > build/lib.linux-i686-2.4/matplotlib/mpl-data > running build_ext > building 'matplotlib.backends._wxagg' extension > C compiler: > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes > -fPIC > > compile > options: '-DGTK_NO_CHECK_CASTS -D__WXGTK__ -D_FILE_OFFSET_BITS=64 > -D_LARGE_FILES -D_LARGEFILE_SOURCE=1 -DNO_GCC_PRAGMA -I/usr/include/libpng12 > -I/usr/local/include -I/usr/include -I. > -I/var/lib/python-support/python2.4/numpy/core/include -Isrc -Iagg24/include > -I. -I/usr/include/freetype2 -I/usr/local/include -I/usr/include -I. > -I/usr/lib/wx/include/gtk2-unicode-release-2.6 -I/usr/include/wx-2.6 > -I/usr/include/python2.4 -c' > gcc: src/_wxagg.cpp > cc1plus: warning: command line option "-Wstrict-prototypes" is valid for > Ada/C/ObjC but not for C++ > In file included from /usr/include/python2.4/Python.h:8, > from ./CXX/WrapPython.h:47, > from ./CXX/Extensions.hxx:48, > from src/_backend_agg.h:8, > from src/_wxagg.cpp:48: > /usr/include/python2.4/pyconfig.h:851:1: warning: "_POSIX_C_SOURCE" redefined > In file included from /usr/include/string.h:26, > > from > /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring:52, > from src/_wxagg.cpp:38: > /usr/include/features.h:150:1: warning: this is the location of the previous > definition > src/_wxagg.cpp:55:34: error: wx/wxPython/wxPython.h: No such file or directory > src/_wxagg.cpp: In member function 'Py::Object > _wxagg_module::convert_agg_to_wx_image(const Py::Tuple&)': > src/_wxagg.cpp:103: error: 'wxPyConstructObject' was not declared in this > scope > src/_wxagg.cpp: In member function 'Py::Object > _wxagg_module::convert_agg_to_wx_bitmap(const Py::Tuple&)': > src/_wxagg.cpp:125: error: 'wxPyConstructObject' was not declared in this > scope > src/_wxagg.cpp: In function 'void init_wxagg()': > src/_wxagg.cpp:253: error: 'wxPyCoreAPI_IMPORT' was not declared in this scope > /var/lib/python-support/py
Re: [Matplotlib-users] build matplotlib including backend wxPython
On Jan 22, 2008, at 11:00 AM, Matthias Michler wrote: > > I was not up to date with my installation and I tried to use the > latest svn > version (trunk) on my Debian etch. I have a problem to build > matplotlib > including support for wxPython as backend. The output is attached > below. > > Actually I cannot find a file "wxPython.h" on my system. The wxPython Debian packages do not include the development headers required to build the WXAgg accelerator module. The WXAgg backend will work just fine without it, so you should disable the module by editing setup.cfg and uncommenting the line "wxagg = False" in the "gui_support" section. Please let me know if you haven't created a setup.cfg file and are receiving this error straight "out of the box", as that's indicative of a bug in the build system. Thanks! Ken - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
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/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Problem with cygwin/ipython interactive mode
Hi there, I feel like I am really close to getting matplotlib working under cygwin/ipython (although the problem persists in the conventional python shell also). On a more general note it seems there are dozens of different ways to run matplotlib under windows. I used as many cygwin packages as seemed relvant including the cygwin version of python and X etc. I then installed numpy and ipython from source (following the linux instructions). I tried to install pygtk and wxpython without success (also from source). I am a bit confused in this situation when I should follow windows installation and when I should follow unix e.g. Windows installers of python packages appear not to work at all... There were only two minor issues. I had to run ash / rebaseall Also I had to create the following symbolic links : cd /lib ln -s libtk84.a libtk8.4.a ln -s libtcl84.a libtcl8.4.a Anyway my problem is the following : from pylab import * from numpy import * contour(eye(100)) show() This then produces the image and the function show() blocks on the shell. This is all normal behaviour (it also happens in linux). However If I then close the window and then type : contour(eye(100)) A "Figure 1" window appears, but nothing happens in it (on linux the contour plot would reappear). in this situation show() also does nothing. From this point on nothing I do can make the figure plot... I checked the instructions on : http://matplotlib.sourceforge.net/interactive.html and have used the config file there with minor changes for TkAgg and interactive mode. However this also did not work. Note : again under cygwin I placed the file in ~/.matplotlib/matplotlibrc rather than the suggested windows location and this seemed to work. While interactive mode is useful it is not mandatory for what I am doing and perhaps the easiest thing to do is set matplotlib to dump all output to files... Thanks in advance for any help! David - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users