Jeffrey Wise wrote: > Hi, > > I'm in my first week with PIL and doing well - it's a tremendous library! > I've gotten to the point in my image analysis that I need to find all the > groups of connected pixels in an image. These groups form arbitrary shapes > in the image. I want to preserve the shape information for each group, so I > can compare/analyze/categorize... it later. > > The image is composed of pixels of value 0 or 255 in "L" B&W format. I > assume such an algorithm will need to find a pixel of value 255 and then > check in every direction about it for a neighbor that is 255 too. The > algorithm would presumably recurse to find neighbors of the neighbor, etc. > I suspect the trick in this algorithm is the data structures needed to keep > track of the discovered adjacencies. I have loaded the image into the 2D > array-like accessor, so I have free access to each pixel. > > I haven't noticed such an algorithm in the PIL yet; maybe I've missed it. > Or perhaps there is Python code available to do this algorithm? Any ideas?
Jeff, You can take a look at some code from Pyrobot, Python Robotics, that was written by a student: http://cvs.cs.brynmawr.edu/cgi-bin/viewcvs.cgi/pyrobot/vision/__init__.py?rev=HEAD&content-type=text/vnd.viewcvs-markup Start with the Blob class. We also have similar code in C++, and wrapped by Python using SWIG: http://cvs.cs.brynmawr.edu/cgi-bin/viewcvs.cgi/pyrobot/vision/cvision/Vision.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup If you are interested in image processing, robotics, or other camera-based functions, see our course materials here: http://pyrorobotics.org/?page=PyroModuleComputerVision -Doug > Thanks, > .Jeff Wise > > > _______________________________________________ > Image-SIG maillist - Image-SIG@python.org > http://mail.python.org/mailman/listinfo/image-sig > _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig