The task is straightforward. I want to select a certain region of an image and plot, for example, the distribution of pixel values within that region. Therefore, I want to have the pixels coordinates so that I can select those pixel to get their values.
What I am doing now is to use canvas to display the image and define callbacks attached to mouse click events to generate an object that encloses the region I want to have. The trouble I have now is that after I generate a (for example) polygon object in a canvas, I do not know how I can get all pixels enclosed by the polygon object. I am new to Tkinter and I think there must be an easy way to get it done. Thanks, Yahui On Tue, 2011-06-21 at 10:04 -0700, Lion Kimbro wrote: > > > 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 <yah...@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, <yah...@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@python.org > > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > > > _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss