Cross hair and polygon drawing tools.

Hi,

I'm looking for something analogous to Matlab's ginput() and roipoly().

ginput() basically displays a crosshair on the current figure and allows us to select points by clicking on it. It returns the x,y coordinates of the points.

roipoly() allows us to define a polygon by clicking on the figure and returns a logical matrix, where ones represent the insides of the polygon and zeros outside.

Any pointers are appreciated.

I recently found matplotlib and started porting some of my Matlab scripts to it.

Ubuntu feisty (7.04), matplotlib 0.87.7. I can upgrade though.

Thanks,
Venkat.

Hi,

···

On Thursday 06 December 2007 19:39:59 Venkat Ramanan wrote:

I'm looking for something analogous to Matlab's ginput() and roipoly().

I'm no expert on this, but have a look at the lasso_demo.py example, which
shows something akin to roipoly(), and pick_event_demo.py and
pick_even_demo2.py, which show something like ginput() (although I think no
cross hairs :D).

I hope that's useful to you,
Jose

Check out cursor_demo.py and matplotlib.widgets.Cursor for cross hairs.

···

On Friday 07 December 2007 7:19:04 am José Gómez-Dans wrote:

Hi,

On Thursday 06 December 2007 19:39:59 Venkat Ramanan wrote:
> I'm looking for something analogous to Matlab's ginput() and roipoly().

I'm no expert on this, but have a look at the lasso_demo.py example, which
shows something akin to roipoly(), and pick_event_demo.py and
pick_even_demo2.py, which show something like ginput() (although I think no
cross hairs :D).

Thanks for the pointer. The matplotlib.widget.Cursor works much better for displaying crosshairs. ( due to blitting? )

I still haven't found a tool yet for drawing a polygon. The lasso_demo.py doesn't run on my system. Well, it runs, displays a scatter of points, but I'm not sure what is it supposed to do next.

Thanks,
Venkat.
PS: Sorry for personal post, I meant to post to the list but forgot to 'reply all'

Darren Dale wrote:

···

On Friday 07 December 2007 7:19:04 am Jos� G�mez-Dans wrote:
  

Hi,

On Thursday 06 December 2007 19:39:59 Venkat Ramanan wrote:
    

I'm looking for something analogous to Matlab's ginput() and roipoly().
      

I'm no expert on this, but have a look at the lasso_demo.py example, which
shows something akin to roipoly(), and pick_event_demo.py and
pick_even_demo2.py, which show something like ginput() (although I think no
cross hairs :D).
    
Check out cursor_demo.py and matplotlib.widgets.Cursor for cross hairs.

-------------------------------------------------------------------------
SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
  
--
Venkat Ramanan,
Research Associate,
Imaging Research,
Sunnybrook Health Sciences Centre,
2075 Bayview Ave,
Toronto-M4N3M5
Ontario, Canada

For some simple but effective Python code you can use to create a mask
similar to that provided by the Matlab roipoly function, see
http://www.ariel.com.au/a/python-point-int-poly.html
http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be
quite effective.

Venkat Ramanan wrote:

···

Hi,

I'm looking for something analogous to Matlab's ginput() and roipoly().

ginput() basically displays a crosshair on the current figure and allows
us to select points by clicking on it. It returns the x,y coordinates of
the points.

roipoly() allows us to define a polygon by clicking on the figure and
returns a logical matrix, where ones represent the insides of the
polygon and zeros outside.

Any pointers are appreciated.

I recently found matplotlib and started porting some of my Matlab
scripts to it.

Ubuntu feisty (7.04), matplotlib 0.87.7. I can upgrade though.

Thanks,
Venkat.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/Cross-hair-and-polygon-drawing-tools.-tp14199642p14626348.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

matplotlib implements these algorithms in C -- see
matplotlib.nxutils.pnpoly for a testing inclusion of a single point,
and matplotlib.nxutils.points_inside_poly for testing multiple points.
There is some example code using the latter function at
http://matplotlib.sf.net/examples/lasso_demo.py. Not sure why this
example is not working for Venkat.

JDH

···

On Jan 4, 2008 4:33 PM, Mephisto <dr_tyson@...32...> wrote:

For some simple but effective Python code you can use to create a mask
similar to that provided by the Matlab roipoly function, see
http://www.ariel.com.au/a/python-point-int-poly.html
http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be
quite effective.

John Hunter wrote:

···

On Jan 4, 2008 4:33 PM, Mephisto <dr_tyson@...32...> wrote:

For some simple but effective Python code you can use to create a mask
similar to that provided by the Matlab roipoly function, see
http://www.ariel.com.au/a/python-point-int-poly.html
http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be
quite effective.

matplotlib implements these algorithms in C -- see
matplotlib.nxutils.pnpoly for a testing inclusion of a single point,
and matplotlib.nxutils.points_inside_poly for testing multiple points.
There is some example code using the latter function at
http://matplotlib.sf.net/examples/lasso_demo.py. Not sure why this
example is not working for Venkat.

This is probably not the reason for Venkat (I think he said he was using 0.87)... but lasso_demo.py is currently broken on the trunk, and working for me in 0.91.2. I'm looking into it.

Cheers,
Mike

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I do this sort of stuff all of the time. I have a tool that is interactive, making a polygon that you can edit (similar to poly_editor in the examples), that is linked to the polygeom class below, but it is broken in the new transforms release of the code.

poly_editor is also broken, by the way. You can't insert a point anymore.

For now, you can use these simpler tools:

Good luck,

-Rob

ginput.py (552 Bytes)

polygeom.py (8.61 KB)

Hi all,

Thanks for the helpful responses.

I had switched back to Matlab, meanwhile.

lasso_demo.py does look close to what I had wanted to implement. Earlier, while checking it out, I must have right-clicked first and after that it didn't seem to work ( perhaps a bug? ).

I'll look in to Rob's solution as well, once I upgrade to the latest release.

Thanks,
Venkat.

Michael Droettboom wrote:

···

John Hunter wrote:
  

On Jan 4, 2008 4:33 PM, Mephisto <dr_tyson@...32...> wrote:
    

For some simple but effective Python code you can use to create a mask
similar to that provided by the Matlab roipoly function, see
http://www.ariel.com.au/a/python-point-int-poly.html
http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be
quite effective.
      

matplotlib implements these algorithms in C -- see
matplotlib.nxutils.pnpoly for a testing inclusion of a single point,
and matplotlib.nxutils.points_inside_poly for testing multiple points.
There is some example code using the latter function at
http://matplotlib.sf.net/examples/lasso_demo.py. Not sure why this
example is not working for Venkat.
    
This is probably not the reason for Venkat (I think he said he was using 0.87)... but lasso_demo.py is currently broken on the trunk, and working for me in 0.91.2. I'm looking into it.

Cheers,
Mike

--
Venkat Ramanan,
Research Associate,
Imaging Research,
Sunnybrook Health Sciences Centre,
2075 Bayview Ave,
Toronto-M4N3M5
Ontario, Canada

lasso_demo.py is working again on the trunk.

The problem was not transforms related. The problem is in the way the colors were being updated after the markers were selected. On the trunk, the set of facecolors in a collection is stored as a numpy array for efficiency. This meant that the facecolor Python list that lasso_demo.py was updating was no longer the same object as the facecolor Numpy array that was actually used for drawing. I added a get_facecolors() method to Collection, and that is now used to update the colors in the collection.

See r4877 for a set of changes.

http://matplotlib.svn.sourceforge.net/viewvc/matplotlib?view=rev&revision=4877

Cheers,
Mike

Michael Droettboom wrote:

···

John Hunter wrote:

On Jan 4, 2008 4:33 PM, Mephisto <dr_tyson@...32...> wrote:

For some simple but effective Python code you can use to create a mask
similar to that provided by the Matlab roipoly function, see
http://www.ariel.com.au/a/python-point-int-poly.html
http://www.ariel.com.au/a/python-point-int-poly.html . The code seems to be
quite effective.

matplotlib implements these algorithms in C -- see
matplotlib.nxutils.pnpoly for a testing inclusion of a single point,
and matplotlib.nxutils.points_inside_poly for testing multiple points.
There is some example code using the latter function at
http://matplotlib.sf.net/examples/lasso_demo.py. Not sure why this
example is not working for Venkat.

This is probably not the reason for Venkat (I think he said he was using 0.87)... but lasso_demo.py is currently broken on the trunk, and working for me in 0.91.2. I'm looking into it.

Cheers,
Mike

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

It looks as if poly_editor is broken in 0.91.2 and the trunk. Is that your observation as well?

This has been fixed in SVN (on both the trunk and the 0.91.x branch).

On both versions, the line (that makes up the draggable markers) was never added to the axes, so it doesn't get a transform, and all the markers are drawn in the lower left.

For the trunk, there were a couple updates to use the new transforms methods. Also, numpy arrays (which are now used for the polygon data) do not support insertion, so the call to "insert" had to be rewritten as creating a new array.

See r4878 (trunk) and r4879 (0.91.x maintenance).

Cheers,
Mike

Rob Hetland wrote:

···

I do this sort of stuff all of the time. I have a tool that is interactive, making a polygon that you can edit (similar to poly_editor in the examples), that is linked to the polygeom class below, but it is broken in the new transforms release of the code.

poly_editor is also broken, by the way. You can't insert a point anymore.

For now, you can use these simpler tools:

Good luck,

-Rob

------------------------------------------------------------------------

On Dec 6, 2007, at 8:39 PM, Venkat Ramanan wrote:

Hi,

I'm looking for something analogous to Matlab's ginput() and roipoly().

ginput() basically displays a crosshair on the current figure and allows
us to select points by clicking on it. It returns the x,y coordinates of
the points.

roipoly() allows us to define a polygon by clicking on the figure and
returns a logical matrix, where ones represent the insides of the
polygon and zeros outside.

Any pointers are appreciated.

I recently found matplotlib and started porting some of my Matlab
scripts to it.

Ubuntu feisty (7.04), matplotlib 0.87.7. I can upgrade though.

Thanks,
Venkat.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

----

Rob Hetland, Associate Professor

Dept. of Oceanography, Texas A&M University

http://pong.tamu.edu/~rob

phone: 979-458-0096, fax: 979-845-6331

------------------------------------------------------------------------

-------------------------------------------------------------------------
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

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

It looks as if poly_editor is broken in 0.91.2 and the trunk. Is that
your observation as well?

Yes.

This has been fixed in SVN (on both the trunk and the 0.91.x branch).

On both versions, the line (that makes up the draggable markers) was
never added to the axes, so it doesn't get a transform, and all the
markers are drawn in the lower left.

For the trunk, there were a couple updates to use the new transforms
methods. Also, numpy arrays (which are now used for the polygon data)
do not support insertion, so the call to "insert" had to be rewritten as
creating a new array.

Yes, I think this is part of the problem, but have not had the time to dig into it yet. But your description of the problem matches the error messages I was getting.

Also, I find this such a useful tool, I wonder if it would be worthwhile putting it somewhere in the matplotlib tree explicitly? Even better as a class that could be subclassed..

-Rob

···

On Jan 18, 2008, at 7:00 PM, Michael Droettboom wrote:

----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331

Rob Hetland wrote:

It looks as if poly_editor is broken in 0.91.2 and the trunk. Is that
your observation as well?

Yes.

This has been fixed in SVN (on both the trunk and the 0.91.x branch).

On both versions, the line (that makes up the draggable markers) was
never added to the axes, so it doesn't get a transform, and all the
markers are drawn in the lower left.

For the trunk, there were a couple updates to use the new transforms
methods. Also, numpy arrays (which are now used for the polygon data)
do not support insertion, so the call to "insert" had to be rewritten as
creating a new array.

Yes, I think this is part of the problem, but have not had the time to dig into it yet. But your description of the problem matches the error messages I was getting.

Also, I find this such a useful tool, I wonder if it would be worthwhile putting it somewhere in the matplotlib tree explicitly? Even better as a class that could be subclassed..

I think that would be worthwhile just to avoid (well, reduce) these problems when interface changes occur in the future. Since you were forced to copy-and-paste poly_editor as a starting point, rather than inheriting from it, there's little you can do to move forward now other than to manually update your own code.

I'm not opposed to the idea, but maybe we should take a survey of how it's being used now to make sure whatever it ends up looking like is sufficient.

Cheers,
Mike

···

On Jan 18, 2008, at 7:00 PM, Michael Droettboom wrote:

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I think that would be worthwhile just to avoid (well, reduce) these
problems when interface changes occur in the future. Since you were
forced to copy-and-paste poly_editor as a starting point, rather than
inheriting from it, there's little you can do to move forward now other
than to manually update your own code.

Yes, that sucks, and I feel sorry for my self every time I have to do it...

I'm not opposed to the idea, but maybe we should take a survey of how
it's being used now to make sure whatever it ends up looking like is
sufficient.

I of course, am in favor. It might also be a case of 'if we build it, they will come.'

-Rob

···

On Jan 18, 2008, at 8:42 PM, Michael Droettboom wrote:

----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331