Areas of contours

Maik Riechert maik.riechert at arcor.de
Wed Sep 10 08:28:36 EDT 2014


My goal is to determine the biggest contour that covers 1's in the binary 
image and return it, therefore I thought I first use find_contours and then 
calculate the area of each contour to get the right one. I'm not sure if 
regionprops helps me here. In the meantime I adapted a function from 
stackoverflow:

def polygonArea(poly):
    """
    Return area of an unclosed polygon.
    
    :see: https://stackoverflow.com/a/451482
    :param poly: (n,2)-array
    """
    # we need a plain list for the following operations
    if isinstance(poly, np.ndarray):
        poly = poly.tolist()
    segments = zip(poly, poly[1:] + [poly[0]])
    return 0.5 * abs(sum(x0*y1 - x1*y0
                         for ((x0, y0), (x1, y1)) in segments))

Before using that function I un-close the returned contours.

Cheers
Maik

Am Mittwoch, 10. September 2014 11:43:59 UTC+2 schrieb Juan Nunez-Iglesias:
>
> Hey Maik,
>
> Can you be a bit more specific? The pipeline may need to be a bit 
> different, but this seems doable. In particular, regionprops(image)[i].area 
> will return the area of all binary-labeled regions.
>
> If that doesn’t help, if you have an example image with code it might be 
> easier to translate your workflow.
>
> Note that we don’t attempt to offer feature parity with OpenCV, which has 
> a lot of hard computer vision algorithms that we lack. But this in 
> particular should be doable.
>
> Juan.
>> Sent from Mailbox <https://www.dropbox.com/mailbox> 
>
>
> On Wed, Sep 10, 2014 at 7:40 PM, Maik Riechert <maik.r... at arcor.de 
> <javascript:>> wrote:
>
>> Hi,
>>
>> I'm currently switching from OpenCV to scikit-image and came to a point 
>> where I miss a certain feature.
>>
>> In OpenCV I used findContours() and then contourArea() to calculate the 
>> area of each contour. I couldn't find this in scikit-image. If I didn't 
>> miss it somewhere, could that be added as a new function?
>>
>> Thanks
>> Maik
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "scikit-image" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to scikit-image... at googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20140910/b5743624/attachment.html>


More information about the scikit-image mailing list