[SciPy-user] circumference in raster image
Wed Jul 8 07:38:51 CDT 2009
Zachary Pincus wrote:
> 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.
Thank you very much, I will try your code. This is the way I thought I
might try (interpolating by a smooth function/polynomial), so it's cool
I do not have to dive into it :-)
I would like to use it within my BSD code , so it would be awesome if
you relicensed the code to BSD.
> On Jul 7, 2009, at 4:22 PM, Sebastian Haase wrote:
>> On Tue, Jul 7, 2009 at 8:34 PM, Zachary
>> Pincus<firstname.lastname@example.org> 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.
>> Hi Zach,
>> I would also be interested in that code - if you don't mind sending me
>> a copy ....
> SciPy-user mailing list
More information about the SciPy-user