[Tkinter-discuss] how to get all pixels enclosed by a canvas object

Lion Kimbro lionkimbro at gmail.com
Tue Jun 21 19:04:07 CEST 2011


  Are you talking about making, say, a clickable image-map ..?
  Or perhaps semantic regions? [1]

  I guess what I'm wondering is:
  * Why do you need to get all of the pixel coordinates within the region
(within the shape,)
  * ...and:  is there an easier way to do what you are wanting to do?

  For example, if you were wanting to make a clickable image-map,
  then I'd want to check, "Do you know that you can attach events to clicks
  on the objects in the canvas?"

  Or if you are trying to do collision detection, you might want to look at:

http://www.rhinocerus.net/forum/lang-tcl/597392-overlapping-items-tk-canvas.html
  ...or you might want to use canvas.find_overlapping dynamically,
  rather than getting at the original data, ...

  (etc.,.)


[1] Semantic Regions
  http://hcil.cs.umd.edu/trs/2004-05/2004-05-revised.pdf


On Tue, Jun 21, 2011 at 6:20 AM, Peng <yahuip at uchicago.edu> wrote:

> Thanks for your reply, Lion.
>
> What I want to do is to select a region of interest (ROI) in a given
> image.  I can display the image in a canvas widget and use
> canvas.create_#object#() method to generate an ROI on the screen.
> However, I could not find a way to get all pixel coordinates inside the
> ROI.  I have found that canvas.coors() returns pixel coordinates but
> they do not normally form a close contour.  What I was wondering is
> whether there is a simple way to get all pixels inside an object that is
> created by canvas.create_#object#() method.
>
> I see your suggestion is a possible way: get the bbox() return values
> for the object and test each pixel (or a small box) to see whether or
> not it is inside the object.  But are there easier and more direct ways
> to do this?
>
> Yahui
>
> On Mon, 2011-06-20 at 23:39 -0700, Lion Kimbro wrote:
> >
> >   I'm not sure what you mean, but perhaps you are looking for:
> >
> > canvas.find_enclosed(x1, y1, x2, y2)     => [objID, objID, ...]
> > completely enclosed
> > canvas.find_overlapping(x1, y1, x2, y2)  => [objID, objID, ...]
> > sharing at least 1 point
> >
> >   ..?
> >
> >
> > On Mon, Jun 20, 2011 at 7:59 PM, <yahuip at uchicago.edu> wrote:
> >         Hi there,
> >
> >         I have been struggling to find a way to retrieve all pixel
> >         coordinates that are enclosed by an object drawn on a canvas
> >         widget.  Anyone knows how I can do it?
> >
> >         Thanks,
> >         Yahui
> >         _______________________________________________
> >         Tkinter-discuss mailing list
> >         Tkinter-discuss at python.org
> >         http://mail.python.org/mailman/listinfo/tkinter-discuss
> >
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110621/9feed01b/attachment.html>


More information about the Tkinter-discuss mailing list