[SciPy-user] circumference in raster image

Zachary Pincus zachary.pincus@yale....
Tue Jul 7 13:34:04 CDT 2009


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



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.
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list