[ITK-users] Strange coordinates output by itk::ContourExtractor2DImageFilter

沈庄明 zhuangming.shen at sphic.org.cn
Mon Mar 14 23:00:43 EDT 2016


Hi all,


I used itk::ContourExtractor2DImageFilter to extract contours from a binary image (i.e. only 0 or 255 for pixel intensity). Mostly, the code can work correctly. However, the code sometimes outputs very strange coordinates (e.g. (194.0, 5.36011819173e-320) ), which should represent the path of the contour. When I change the contour value from 0 to other number no less than 255 (i.e. 250), I got more strange coordinates. My code and results are listed as below. Has anyone met the same situation?​



Regards,


Zhuangming Shen




Here is my code

=======================================================================================

import itk

reader = itk.ImageFileReader[itk.Image.UC2].New()
reader.SetFileName("test.nii")
reader.Update()

contour_extractor = itk.ContourExtractor2DImageFilter[itk.Image.UC2].New()
contour_extractor.SetInput(reader.GetOutput())
contour_extractor.SetContourValue(0)
contour_extractor.Update()

contour_number = contour_extractor.GetNumberOfOutputs()

print("There are "+str(contour_number)+" contours")

for k in xrange(contour_number):
    print("================  Contour "+str(k)+" ================")

    point_number = contour_extractor.GetOutput(k).GetVertexList().Size()
    print("Point number: "+str(point_number))

    for i in xrange(point_number):
        print("("+str(contour_extractor.GetOutput(k).GetVertexList().GetElement(i)[0])+","+str(contour_extractor.GetOutput(0).GetVertexList().GetElement(i)[1])+")")




Here is my results

=========================================================================================

There are 2 contours
================  Contour 0 ================
Point number: 670
(373.0,380.0)
(372.0,380.0)
(371.0,380.0)
(370.0,380.0)
(369.0,380.0)
(368.0,380.0)
(367.0,380.0)
...
(375.0,379.0)
(374.0,379.0)
(373.0,380.0)
================  Contour 1 ================
Point number: 677
(188.0,380.0)
(187.0,380.0)
(186.0,380.0)
(185.0,380.0)
...
(198.0,379.0)
(197.0,379.0)
(196.0,379.0)
(195.0,380.0)
(194.0,5.36011819173e-320)
(193.0,382.0)
(192.0,382.0)
(191.0,382.0)
(190.0,382.0)
(189.0,382.0)
(188.0,382.0)




Here is the input test.nii
=============================================================================================
[cid:beaa107f-9827-40b6-aac6-cdb30092e744]​

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160315/760c4b9f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 8798 bytes
Desc: pastedImage.png
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160315/760c4b9f/attachment.png>


More information about the Insight-users mailing list