[SciPy-user] circumference in raster image

Sebastian Haase seb.haase@gmail....
Tue Jul 7 15:22:47 CDT 2009

On Tue, Jul 7, 2009 at 8:34 PM, Zachary Pincus<zachary.pincus@yale.edu> wrote:
> Hi Robert,
> Basically, assuming the object is in a binarized array, you could use
> ndimage to do one iteration of erosion, giving you the same object but
> one pixel smaller. Then xor the eroded and original binary images to
> give an image where the single-pixel border around the object is 1 and
> the rest is zero; from here you can just sum the pixels to give a
> (very rough) perimeter value. (Note of course that this doesn't
> account for the spacing between pixels being different on the diagonal
> than horizontal or vertical... for that you'd need some chain code
> things, which I think ndimage doesn't provide.)
> Personally, in situations like these -- especially when the original
> image is not binary and I'd need to threshold to get a binary image --
> I usually run a marching-squares algorithm over the data to extract
> interpolated iso-intensity contours for a particular threshold; these
> contours are polygons with which it is easy to calculate fairly
> accurate perimeter, area, etc. values. I can send a C extension that
> does this very quickly, if desired.
> Zach
Hi Zach,
I would also be interested in that code - if you don't mind sending me
a copy ....


> On Jul 7, 2009, at 1:42 PM, Robert Cimrman wrote:
>> Hi!
>> Hoping that there are some raster image experts around: I need to
>> compute an approximation of circumference of an object (with smooth
>> boundary) represented as a filled area in a 2d array. Can
>> scipy.ndimage
>> deal with that?
>> thanks,
>> r.

More information about the SciPy-user mailing list