[SciPy-user] circumference in raster image

Zachary Pincus zachary.pincus at yale.edu
Tue Jul 7 16:56:32 EDT 2009


Hi all,

Attached is find_contours, an extension module that finds all contours  
in a 2D array at a specified iso-value. The contour position is  
linearly interpolated between pixels. Let me know if you have any  
questions, etc. (Looking over the code, I'm surprised how well I  
documented and commented it... lucky break for anyone who wants to use  
or modify it, I guess.) It's GPL because it comes from a larger GPL'd  
project of mine, but just ask me and I'll send it under a different  
license.

Zach


On Jul 7, 2009, at 4:22 PM, Sebastian Haase wrote:

> On Tue, Jul 7, 2009 at 8:34 PM, Zachary  
> Pincus<zachary.pincus at 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 ....
>
> Thanks,
> Sebastian
>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: find_contours.zip
Type: application/zip
Size: 6411 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090707/7f86c182/attachment.zip>


More information about the SciPy-User mailing list