Areas of contours
Johannes Schönberger
jsch at demuc.de
Wed Sep 10 09:24:39 EDT 2014
Hi Maik,
region props let's you also get the image of the separated region (separated meaning, only containing pixels where label == i) through `prop.image` or `prop.filled_image`.
Hope it helps.
Johannes Schönberger
On Sep 10, 2014, at 9:19 AM, Maik Riechert <maik.riechert at arcor.de> wrote:
> Hi Juan,
>
> how would I do step 5? Even if I know the bounding box it could still be that parts of other regions are in the box, right?
>
> I'm not sure if all that would be a bit too slow if it worked. My images are 4000x3000 and I guess there's a noticeable performance advantage of doing all further calculations just on the contours instead of the image itself.
>
> Cheers
> Maik
>
> Am Mittwoch, 10. September 2014 15:04:27 UTC+2 schrieb Juan Nunez-Iglesias:
> Hey Maik,
>
> But what about:
>
> 1) Do a scipy.ndimage.binary_fill_holes to ensure that objects constitute the full area from a contour
> 2) Do a scipy.ndimage.label to give a unique ID to each blob of 1s in the image.
> 3) get props = skimage.regionprops(im) to get the properties of each blob
> 4) you can then find the argmax of [p.area for p in props]
> 5) you can then compute the contour of just that object, and offset the coordinates using the .bbox property
>
> Would this work? It all depends on your purposes, and I’m also not sure which would be most efficient.
>
> Juan.
> —
> Sent from Mailbox
>
>
> On Wed, Sep 10, 2014 at 10:29 PM, Maik Riechert <maik.r... at arcor.de> wrote:
>
> 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
>
>
> On Wed, Sep 10, 2014 at 7:40 PM, Maik Riechert <maik.r... at arcor.de> 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.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
More information about the scikit-image
mailing list