[Insight-users] LabelStatisticsImageFilter's GetValidLabels depends upon volume image type?

Richard Beare richard.beare at gmail.com
Fri Nov 30 21:55:22 EST 2012


What happens if you use some other nifti tool, such as fslstats, to
query the image range? Perhaps the nifti conversion has done something
unexpected.

On Sat, Dec 1, 2012 at 10:06 AM, David Welch <david.m.welch at gmail.com> wrote:
> Hello all,
>
> I've run into this behavior when reading in a Freesurfer label file that was
> converted to nifti format (64-bit float):
>
> import SimpleITK as sitk
> temp = sitk.ReadImage(label_file)
> newVol = sitk.ReadImage(fMRI_single_vol_file)
> print temp.GetPixelIDTypeAsString()
> print newVol.GetPixelIDTypeAsString()
>
> labelStat1 = sitk.LabelStatisticsImageFilter()
> labelStat1.Execute(temp, sitk.Cast(newVol, sitk.sitkUInt16))
>
> labelStat2 = sitk.LabelStatisticsImageFilter()
> labelStat2.Execute(temp, sitk.Cast(newVol, sitk.sitkUInt32))
>
> print labelStat1.GetValidLabels()
> print "=========================================="
> print labelStat2.GetValidLabels()
> assert labelStat1.GetValidLabels() == labelStat2.GetValidLabels(), "Valid
> labels are not the same!"
>
> --------------------------- RESULTS: -------------------------
>
> 64-bit float
>
> 32-bit float
>
> ---------------------------------------------------------------------------
> AssertionError                            Traceback (most recent call last)
> <ipython-input-19-873f6fd284b8> in <module>()
>       8 print "=========================================="
>       9 print labelStat2.GetValidLabels()
> ---> 10 assert labelStat1.GetValidLabels() == labelStat2.GetValidLabels(),
> "Valid labels are not the same!"
>
> AssertionError: Valid labels are not the same!
>
> (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
> 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
> 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
> 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 65501,
> 65502, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513,
> 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524,
> 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535)
> ==========================================
> (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
> 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
> 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
> 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 4294967261,
> 4294967262, 4294967264, 4294967265, 4294967266, 4294967267, 4294967268,
> 4294967269, 4294967270, 4294967271, 4294967272, 4294967273, 4294967274,
> 4294967275, 4294967276, 4294967277, 4294967278, 4294967279, 4294967280,
> 4294967281, 4294967282, 4294967283, 4294967284, 4294967285, 4294967286,
> 4294967287, 4294967288, 4294967289, 4294967290, 4294967291, 4294967292,
> 4294967293, 4294967294, 4294967295)
>
>
> The label values should have a max at ~2350 and  the length of the returned
> lists is LONGER than the length of labels in the label image, so I can't see
> how this could be caused by my choice of cast type…
>
> If I DON'T cast the image file to a lower bit, I get the error:
> ---------------------------------------------------------------------------
>
> RuntimeError                              Traceback (most recent call last)
> <ipython-input-28-605e85d6adb9> in <module>()
>       3 # statMap1 = labelStat.GetLabelStatisticsMap()
>       4 labelStat2 = sitk.LabelStatisticsImageFilter()
> ----> 5 labelStat2.Execute(temp, newVol)
>       6 # statMap2 = labelStat.GetLabelStatisticsMap()
>       7 print labelStat1.GetValidLabels()
>
> /Volumes/scratch/welchdm/bld/latest_BSA/SimpleITK-build/lib/SimpleITK.pyc in
> Execute(self, *args, **kwargs)
>    3712     def Execute(self, *args, **kwargs):
>    3713         """Execute(LabelStatisticsImageFilter self, Image arg2,
> Image arg3) -> Image"""
> -> 3714         return _SimpleITK.LabelStatisticsImageFilter_Execute(self,
> *args, **kwargs)
>    3715
>    3716     def GetMinimum(self, *args, **kwargs):
>
> RuntimeError: Exception thrown in SimpleITK
> LabelStatisticsImageFilter_Execute:
> /Volumes/scratch/welchdm/bld/latest_BSA/SimpleITK/Code/Common/include/sitkDualMemberFunctionFactory.hxx:201:
> sitk::ERROR: Pixel type: 64-bit float is not supported in 3D
> byN3itk6simple26LabelStatisticsImageFilterE
>
>
> Any idea what is going on here?
>
> Cheers,
>
> Dave Welch
> david.m.welch at gmail.com
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list