<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; "><div style="font-family: Calibri, sans-serif; ">Hello all, </div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; ">I've run into this behavior when reading in a Freesurfer label file that was converted to nifti format (64-bit float):</div><div style="font-family: Calibri, sans-serif; "><br></div><div><div><font class="Apple-style-span" face="Courier">import SimpleITK as sitk</font></div><div><font class="Apple-style-span" face="Courier">temp = sitk.ReadImage(label_file)</font></div><div><font class="Apple-style-span" face="Courier">newVol = sitk.ReadImage(fMRI_single_vol_file)</font></div><div><font class="Apple-style-span" face="Courier">print temp.GetPixelIDTypeAsString()</font></div></div><div><font class="Apple-style-span" face="Courier">print newVol.GetPixelIDTypeAsString()</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><div><font class="Apple-style-span" face="Courier">labelStat1 = sitk.LabelStatisticsImageFilter()</font></div><div><font class="Apple-style-span" face="Courier">labelStat1.Execute(temp, sitk.Cast(newVol, sitk.sitkUInt16))</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">labelStat2 = sitk.LabelStatisticsImageFilter()</font></div><div><font class="Apple-style-span" face="Courier">labelStat2.Execute(temp, sitk.Cast(newVol, sitk.sitkUInt32))</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">print labelStat1.GetValidLabels()</font></div><div><font class="Apple-style-span" face="Courier">print "=========================================="</font></div><div><font class="Apple-style-span" face="Courier">print labelStat2.GetValidLabels()</font></div><div><font class="Apple-style-span" face="Courier">assert labelStat1.GetValidLabels() == labelStat2.GetValidLabels(), "Valid labels are not the same!"</font></div></div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; ">--------------------------- RESULTS: -------------------------</div><div style="font-family: Calibri, sans-serif; "><pre>64-bit float</pre><pre>32-bit float</pre><pre><div class="hbox output_area"><div class="box-flex1 output_subarea output_text"><pre><span class="ansired">---------------------------------------------------------------------------</span>
<span class="ansired">AssertionError</span> Traceback (most recent call last)
<span class="ansigreen"><ipython-input-19-873f6fd284b8></span> in <span class="ansicyan"><module></span><span class="ansiblue">()</span>
<span class="ansigreen"> 8</span> <span class="ansigreen">print</span> <span class="ansiblue">"=========================================="</span><span class="ansiblue"></span>
<span class="ansigreen"> 9</span> <span class="ansigreen">print</span> labelStat2<span class="ansiblue">.</span>GetValidLabels<span class="ansiblue">(</span><span class="ansiblue">)</span><span class="ansiblue"></span>
<span class="ansigreen">---> 10</span><span class="ansired"> </span><span class="ansigreen">assert</span> labelStat1<span class="ansiblue">.</span>GetValidLabels<span class="ansiblue">(</span><span class="ansiblue">)</span> <span class="ansiblue">==</span> labelStat2<span class="ansiblue">.</span>GetValidLabels<span class="ansiblue">(</span><span class="ansiblue">)</span><span class="ansiblue">,</span> <span class="ansiblue">"Valid labels are not the same!"</span><span class="ansiblue"></span>
<span class="ansired">AssertionError</span>: Valid labels are not the same!
</pre></div></div><div class="hbox output_area"><div class="prompt"></div><div class="box-flex1 output_subarea output_text output_stream output_stdout"><pre>(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)
</pre></div></div></pre></div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; ">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…</div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; ">If I DON'T cast the image file to a lower bit, I get the error:</div><div style="font-family: Calibri, sans-serif; "><span class="Apple-style-span" style="font-family: monospace; white-space: pre; ">---------------------------------------------------------------------------</span></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><pre><span class="ansired">RuntimeError</span> Traceback (most recent call last)
<span class="ansigreen"><ipython-input-28-605e85d6adb9></span> in <span class="ansicyan"><module></span><span class="ansiblue">()</span>
<span class="ansigreen"> 3</span> <span class="ansired"># statMap1 = labelStat.GetLabelStatisticsMap()</span><span class="ansiblue"></span><span class="ansiblue"></span>
<span class="ansigreen"> 4</span> labelStat2 <span class="ansiblue">=</span> sitk<span class="ansiblue">.</span>LabelStatisticsImageFilter<span class="ansiblue">(</span><span class="ansiblue">)</span><span class="ansiblue"></span>
<span class="ansigreen">----> 5</span><span class="ansired"> </span>labelStat2<span class="ansiblue">.</span>Execute<span class="ansiblue">(</span>temp<span class="ansiblue">,</span> newVol<span class="ansiblue">)</span><span class="ansiblue"></span>
<span class="ansigreen"> 6</span> <span class="ansired"># statMap2 = labelStat.GetLabelStatisticsMap()</span><span class="ansiblue"></span><span class="ansiblue"></span>
<span class="ansigreen"> 7</span> <span class="ansigreen">print</span> labelStat1<span class="ansiblue">.</span>GetValidLabels<span class="ansiblue">(</span><span class="ansiblue">)</span><span class="ansiblue"></span>
<span class="ansigreen">/Volumes/scratch/welchdm/bld/latest_BSA/SimpleITK-build/lib/SimpleITK.pyc</span> in <span class="ansicyan">Execute</span><span class="ansiblue">(self, *args, **kwargs)</span>
<span class="ansigreen"> 3712</span> <span class="ansigreen">def</span> Execute<span class="ansiblue">(</span>self<span class="ansiblue">,</span> <span class="ansiblue">*</span>args<span class="ansiblue">,</span> <span class="ansiblue">**</span>kwargs<span class="ansiblue">)</span><span class="ansiblue">:</span><span class="ansiblue"></span>
<span class="ansigreen"> 3713</span> <span class="ansiblue">"""Execute(LabelStatisticsImageFilter self, Image arg2, Image arg3) -> Image"""</span><span class="ansiblue"></span>
<span class="ansigreen">-> 3714</span><span class="ansired"> </span><span class="ansigreen">return</span> _SimpleITK<span class="ansiblue">.</span>LabelStatisticsImageFilter_Execute<span class="ansiblue">(</span>self<span class="ansiblue">,</span> <span class="ansiblue">*</span>args<span class="ansiblue">,</span> <span class="ansiblue">**</span>kwargs<span class="ansiblue">)</span><span class="ansiblue"></span>
<span class="ansigreen"> 3715</span> <span class="ansiblue"></span>
<span class="ansigreen"> 3716</span> <span class="ansigreen">def</span> GetMinimum<span class="ansiblue">(</span>self<span class="ansiblue">,</span> <span class="ansiblue">*</span>args<span class="ansiblue">,</span> <span class="ansiblue">**</span>kwargs<span class="ansiblue">)</span><span class="ansiblue">:</span><span class="ansiblue"></span>
<span class="ansired">RuntimeError</span>: 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
</pre></span></font></div><div style="font-family: Calibri, sans-serif; "><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><br></span></div><div><span class="Apple-style-span" style="white-space: pre; ">Any idea what is going on here?</span></div><div><span class="Apple-style-span" style="white-space: pre; "><br></span></div><div><span class="Apple-style-span" style="white-space: pre; ">Cheers, </span></div><div><span class="Apple-style-span" style="white-space: pre; "><br></span></div><div><span class="Apple-style-span" style="white-space: pre; ">Dave Welch</span></div><div><span class="Apple-style-span" style="white-space: pre; ">david.m.welch@gmail.com</span></div></body></html>