[ITK] SimpleITK BinaryContour

Lowekamp, Bradley (NIH/NLM/LHC) [C] blowekamp at mail.nih.gov
Thu Aug 3 08:47:13 EDT 2017


Hello,

Yes, in SimpleITK you can very easily split an image and run an operation on it per silice, then join the slices back together. Most of the array like types passed to SimpleITK can be Python lists or tuples and don’t have to be the wrapped type.

You code is verbose and clear, however if you are looking for a more compact and pythonic way, you may consider using a list comprehension.

 sitk.JoinSeries([sitk.BinaryContour(img[:,:,z], fullyConnected=True) for z in range(img.GetSize()[2])])


Brad


From: "E.J. Postema" <e.postema at erasmusmc.nl>
Date: Thursday, August 3, 2017 at 4:24 AM
To: "E.J. Postema" <e.postema at erasmusmc.nl>, 'Dženan Zukic' <dzenanz at gmail.com>
Cc: "community at itk.org" <community at itk.org>
Subject: Re: [ITK] SimpleITK BinaryContour

Hi all,

I have found a solution to my problem. It is pretty easy and straightforward, but I might as well share it anyway.

I split the image across the z-axis and calculate the binary contour of each separate image. So basically run the function per slice instead of the whole volume. Afterwards I join the images again.

Code (Python):

    image = sitk.ReadImage(imageFn)
    depth = image.GetDepth()
    contours = []

    for i in range(depth):
        im = image[:,:,i]
        contour = sitk.BinaryContour(im, fullyConnected=True )
        contours.append(contour)

    vectorOfImages = sitk.VectorOfImage()
    for contour in contours:
        vectorOfImages.push_back(contour)
    img = sitk.JoinSeries(vectorOfImages)

Regards,

Erik



From: Community [mailto:community-bounces at itk.org] On Behalf Of E.J. Postema
Sent: donderdag 3 augustus 2017 09:56
To: 'Dženan Zukic'
Cc: community at itk.org
Subject: Re: [ITK] SimpleITK BinaryContour

Hi Dženan,

Ah Sorry. I get it now. Thanks for the explanation. I will see if I can find another way

Regards,

Erik

From: Dženan Zukić [mailto:dzenanz at gmail.com]
Sent: woensdag 2 augustus 2017 17:04
To: E.J. Postema
Cc: Lambert Zijp; community at itk.org<mailto:community at itk.org>
Subject: Re: [ITK] SimpleITK BinaryContour

Hi Erik,

Lambert's explanation still holds. When a slice you are viewing cuts the surface at an angle close to 90°, you will see a thin line (left and right edges on your contour image). But when it cuts at an angle closer to 0°, you will see some thicker lines (top and bottom). When the slice cuts the surface at exactly 0°, you will see the whole surface.

Example: imaging viewing a slice of a surface representing a cube. If you look at some of the middle slices, you will see a thin empty square. But the first and last slice will be a filled square.

Another example, instead of a cube imagine surface of a staircase, and how slicing it along 2 of the 3 axes will produce "thick" edges.

Regards,
Dženan Zukić, PhD, Senior R&D Engineer, Kitware (Carrboro, N.C.)

On Wed, Aug 2, 2017 at 7:53 AM, E.J. Postema <e.postema at erasmusmc.nl<mailto:e.postema at erasmusmc.nl>> wrote:
Hi Lambert,

Sorry, I forgot to mention that the binary image is the original image and the contour is the result of the BinaryContourImageFilter on that image. So it is a single slice from the stack.

Regards,

Erik



From: Lambert Zijp [mailto:ljzijp at gmail.com<mailto:ljzijp at gmail.com>]
Sent: woensdag 2 augustus 2017 13:44
To: E.J. Postema
Cc: community at itk.org<mailto:community at itk.org>
Subject: Re: [ITK] SimpleITK BinaryContour

Hi Erik,

It might well be that nothing is going wrong; especially binary objects could show such behaviour when creating contours.
The right image could be an end slice of your binary object. The left image can be explained by assuming that the object in the previous or the next slice is larger towards the bottom and much larger towards the top.

Greetings, Lambert

On Wed, Aug 2, 2017 at 11:41 AM, E.J. Postema <e.postema at erasmusmc.nl<mailto:e.postema at erasmusmc.nl>> wrote:
Hi everyone,

So I am trying to create a contour from a binary 3d image. But the results seem a bit weird to me (see the images).
I am expecting a line of 1 (or maybe a few) pixels thick.

Anyone who knows what is going wrong?

Regards,

Erik

_______________________________________________
Community mailing list
Community at itk.org<mailto:Community at itk.org>
http://public.kitware.com/mailman/listinfo/community


_______________________________________________
Community mailing list
Community at itk.org<mailto:Community at itk.org>
http://public.kitware.com/mailman/listinfo/community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20170803/b6600287/attachment-0001.html>


More information about the Community mailing list