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

David M. Welch david.m.welch at gmail.com
Mon Dec 3 11:46:22 EST 2012


Hi all,

I had tried switching the order of the inputs to the Execute command earlier
(see email "Re: [Insight-users] Re  ITK to VTK for 4D images") with a 4D
image.  For some reason lost to the mists of time, I concluded that the
label image needed to be the first input to the filterŠ

Yes, switching the inputs does solve the problem.  Thanks, Hans.

Dave


From:  Hans Johnson <hans-johnson at uiowa.edu>
Date:  Fri, 30 Nov 2012 23:18:02 +0000
To:  "David M. Welch" <david.m.welch at gmail.com>, "insight-users at itk.org"
<insight-users at itk.org>
Cc:  Bradley Lowekamp <blowekamp at mail.nih.gov>, Kent Williams
<norman-k-williams at uiowa.edu>
Subject:  Re: LabelStatisticsImageFilter's GetValidLabels depends upon
volume image type?

David,

You also have the scalar image and the label image backwards in the
"Execute" command.

"temp" is your label image, and it must be integer valued.

"newVol" is your scalar image, and it can be floating point valued.

Hans


From: David Welch <david.m.welch at gmail.com>
Date: Friday, November 30, 2012 5:06 PM
To: "insight-users at itk.org" <insight-users at itk.org>
Cc: Bradley Lowekamp <blowekamp at mail.nih.gov>, Hans Johnson
<hans-johnson at uiowa.edu>, Kent Williams <norman-k-williams at uiowa.edu>
Subject: LabelStatisticsImageFilter's GetValidLabels depends upon volume
image type?

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
---------------------------------------------------------------------------A
ssertionError                            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/sitkDu
alMemberFunctionFactory.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



Notice: This UI Health Care e-mail (including attachments) is covered by the
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential
and may be legally privileged.  If you are not the intended recipient, you
are hereby notified that any retention, dissemination, distribution, or
copying of this communication is strictly prohibited.  Please reply to the
sender that you have received the message in error, then delete it.  Thank
you. 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121203/fda675a5/attachment.htm>


More information about the Insight-users mailing list