<html><head></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; font-family: Calibri, sans-serif; "><div>Hi all,</div><div><br></div><div>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…</div><div><br></div><div>Yes, switching the inputs does solve the problem. Thanks, Hans.</div><div><br></div><div>Dave</div><div><br></div><div><br></div><span id="OLK_SRC_BODY_SECTION"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">From: </span> Hans Johnson <<a href="mailto:hans-johnson@uiowa.edu">hans-johnson@uiowa.edu</a>><br><span style="font-weight:bold">Date: </span> Fri, 30 Nov 2012 23:18:02 +0000<br><span style="font-weight:bold">To: </span> "David M. Welch" <<a href="mailto:david.m.welch@gmail.com">david.m.welch@gmail.com</a>>, "<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>" <<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>><br><span style="font-weight:bold">Cc: </span> Bradley Lowekamp <<a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a>>, Kent Williams <<a href="mailto:norman-k-williams@uiowa.edu">norman-k-williams@uiowa.edu</a>><br><span style="font-weight:bold">Subject: </span> Re: LabelStatisticsImageFilter's GetValidLabels depends upon volume image type?<br></div><div><br></div><div><meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"><div style="word-wrap:break-word; color:rgb(0,0,0); font-size:14px; font-family:Calibri,sans-serif"><div>David,</div><div><br></div><div>You also have the scalar image and the label image backwards in the "Execute" command.</div><div><br></div><div>"temp" is your label image, and it must be integer valued.</div><div><br></div><div>"newVol" is your scalar image, and it can be floating point valued.</div><div><br></div><div>Hans</div><div><br></div><div><br></div><span id="OLK_SRC_BODY_SECTION"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; border-bottom:medium none; border-left:medium none; padding-bottom:0in; padding-left:0in; padding-right:0in; border-top:#b5c4df 1pt solid; border-right:medium none; padding-top:3pt"><span style="font-weight:bold">From: </span>David Welch <<a href="mailto:david.m.welch@gmail.com">david.m.welch@gmail.com</a>><br><span style="font-weight:bold">Date: </span>Friday, November 30, 2012 5:06 PM<br><span style="font-weight:bold">To: </span>"<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>" <<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>><br><span style="font-weight:bold">Cc: </span>Bradley Lowekamp <<a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a>>, Hans Johnson <<a href="mailto:hans-johnson@uiowa.edu">hans-johnson@uiowa.edu</a>>, Kent Williams <<a href="mailto:norman-k-williams@uiowa.edu">norman-k-williams@uiowa.edu</a>><br><span style="font-weight:bold">Subject: </span>LabelStatisticsImageFilter's GetValidLabels depends upon volume image type?<br></div><div><br></div><div><div style="word-wrap:break-word; 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"><a href="mailto:david.m.welch@gmail.com">david.m.welch@gmail.com</a></span></div></div></div></span><br><br><hr>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.
<hr></div></div></span></body></html>