[Insight-users] ContourExtractor2DImageFilter in python
Gaëtan Lehmann
gaetan.lehmann at jouy.inra.fr
Fri Jul 3 06:06:15 EDT 2009
Le 3 juil. 09 à 05:51, Rick Giuly a écrit :
>
> Hello All,
>
> I'm trying to get a contour as a list of points from a binary image
> of a blob. I'm assuming that ContourExtractor2DImageFilter is the
> easiest way to do this, considering what filters are available in
> python. extractor.GetOutputs() returns a DataObjectPointer, I'm not
> sure how to access the individual elements of this in python. Could
> someone advise?
>
> (I will need to access each of the contours and each of the points
> in each contour.)
>
> Thanks
>
> -Rick
>
> ----
>
> import itk
>
> ImageType = itk.Image[itk.F, 2]
> ReaderType = itk.ImageFileReader[ImageType]
>
> reader = ReaderType.New(FileName = "data/A.tiff")
> image = reader.GetOutput()
>
> ExtractorType = itk.ContourExtractor2DImageFilter[ImageType]
>
> extractor = ExtractorType.New()
> extractor.SetInput(image)
> extractor.SetContourValue(100.0)
> extractor.Update()
> print extractor.GetNumberOfOutputs()
> print extractor.GetOutputs()
> # how should I access individual contours?
Hi Rick,
I think you should be able to access all the outputs with the expected
types with
[extractor.GetOutput(i) for i in
range(extractor.GetNumberOfOutputs())]
If you are using wrapitk from googlecode, you can also dow cast a
DataObject to its real type with
itk.down_cast(obj)
or to a specific type with
itk.PolyLineParametricPath[2].cast(obj)
Please let me know if it fix your access problem or not.
Gaëtan
--
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
http://voxel.jouy.inra.fr http://www.itk.org
http://www.mandriva.org http://www.bepo.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090703/b744703a/attachment.pgp>
More information about the Insight-users
mailing list