Hi All,<br><br>I tried to use the SpatialObjectToImageStatisticsCalculator to calculate the volume of the portion overlapping two binary images, temp.mha and temp1.mha, as well as the volume of the two images. I was used to use SpatialObjectToImageStatisticsCalculator to calculate the sum of the image, the volume can be then calculated. However, the sum seems not right. the sum is not equal to the value by iterating all pixels. My concern is that if the filter performs properly.<br>the two images are avaliable at<br>http://www.duke.edu/~kurtzhao/temp.mha<br>http://www.duke.edu/~kurtzhao/temp1.zip<br><br>The output on my machine is <br>overlapping sum from statistical calculator: 4477<br>overlapping sum from volume calculator: 295072<br>sum of temp.mha from statistical calculator: 30425<br>sum of temp.mha from volume calculator: 292569<br>sum of temp1.mha from statistical calculator: 6980<br>sum of temp1.mha from volume calculator: 6980<br><br>Thanks<br><br>Kurt<br><br>#include &lt;iostream&gt;<br>#include &lt;itkImageFileReader.h&gt;<br>#include &lt;itkImageMaskSpatialObject.h&gt;<br>#include &lt;itkSpatialObjectToImageStatisticsCalculator.h&gt;<br><br>#include &lt;itkAddImageFilter.h&gt;<br>#include &lt;itkBinaryThresholdImageFilter.h&gt;<br><br>typedef itk::Image &lt; unsigned char, 3 &gt; ImageVType;<br><br><br>void GetSumV ( ImageVType::Pointer imageP, <br>  ImageVType::Pointer maskImageP, double &amp; sum )<br>  {<br>  const unsigned char PIXELONE = 1 ;<br><br>  typedef itk::AddImageFilter&lt; ImageVType, <br>          ImageVType, ImageVType&gt;  AddType;<br>  AddType::Pointer add = AddType::New ( ) ;<br>  add -&gt; SetInput1 ( imageP);<br>  add -&gt; SetInput2 ( maskImageP);<br>  add -&gt; Update ( ) ;<br>  <br>  typedef itk::BinaryThresholdImageFilter&lt; ImageVType, <br>          ImageVType&gt;  ThresholdType;<br>  ThresholdType::Pointer thresholder <br>    = ThresholdType::New ( ) ;<br>  thresholder -&gt; SetInput ( add -&gt; GetOutput ( )) ;<br>  thresholder -&gt; SetOutsideValue ( 0 ) ;<br>  thresholder -&gt; SetInsideValue ( PIXELONE) ;<br>  thresholder -&gt; SetLowerThreshold ( PIXELONE  ) ;<br>  thresholder -&gt; SetUpperThreshold ( PIXELONE * 2.0 ) ;<br>  thresholder -&gt; Update ( ) ;<br><br>  ImageVType::Pointer image2P = thresholder -&gt; GetOutput ( ) ;<br>  sum = 0 ;<br>  typedef itk::ImageRegionConstIterator&lt; ImageVType &gt; ConstIteratorType;<br>  ConstIteratorType it( image2P , image2P -&gt; GetLargestPossibleRegion ( )  );<br>  for ( it.GoToBegin(); !it.IsAtEnd(); ++it)<br>    {<br>    if ( it.Get( ) == PIXELONE ) <br>      {<br>      sum ++ ;<br>      }<br>    }<br>  }<br>void GetSumS ( ImageVType::Pointer imageP, <br>  ImageVType::Pointer maskImageP, double &amp; sum )<br>  {<br>  typedef itk::ImageMaskSpatialObject&lt;3&gt; ImageMaskSpatialObject;<br>  ImageMaskSpatialObject::Pointer maskSO = ImageMaskSpatialObject::New();<br>  maskSO-&gt;SetImage( maskImageP );<br><br>  typedef itk::SpatialObjectToImageStatisticsCalculator&lt; <br>    ImageVType, ImageMaskSpatialObject&gt; CalculatorType;<br>  CalculatorType::Pointer calculator = CalculatorType::New();<br>  calculator-&gt;SetImage(imageP);<br>  calculator-&gt;SetSpatialObject( maskSO );<br>  calculator-&gt;Update();<br>  /*<br>  std::cout &lt;&lt; &quot;Sample mean = &quot; &lt;&lt; calculator-&gt;GetMean()&lt;&lt;&quot; &quot;;<br>  std::cout &lt;&lt; &quot;Sample STD = &quot; <br>    &lt;&lt; sqrt ( calculator-&gt;GetCovarianceMatrix()[0][0] ) <br>    &lt;&lt; std::endl;<br>  std::cout &lt;&lt; &quot;Sample sum = &quot; <br>    &lt;&lt;  calculator -&gt; GetSum ( ) <br>    &lt;&lt; std::endl;<br>    */<br>  sum =  calculator -&gt; GetSum ( ) ;<br>  } <br>void GetOverlappingSum ( )<br>  {<br><br>  typedef itk::ImageFileReader &lt; ImageVType &gt; ImageReaderType;<br>  ImageReaderType::Pointer reader = ImageReaderType::New();<br>  reader -&gt; SetFileName( &quot;temp.mha&quot; ) ;<br>  reader -&gt; Update();<br><br>  ImageVType::Pointer image = reader -&gt; GetOutput ( ) ;<br><br>  ImageReaderType::Pointer reader1 = ImageReaderType::New();<br>  reader1 -&gt; SetFileName( &quot;temp1.mha&quot; ) ;<br>  reader1 -&gt; Update();<br>  ImageVType::Pointer image1 = reader1 -&gt; GetOutput ( ) ;<br><br>  double sum;<br>  GetSumS ( image, image1, sum ) ;<br>  std::cout&lt;&lt;&quot;overlapping sum from statistical calculator: &quot;<br>    &lt;&lt;sum&lt;&lt;std::endl;<br>  GetSumV ( image, image1, sum ) ;<br>  std::cout&lt;&lt;&quot;overlapping sum from volume calculator: &quot;<br>    &lt;&lt;sum&lt;&lt;std::endl;<br>  GetSumS ( image, image, sum ) ;<br>  std::cout&lt;&lt;&quot;sum of temp.mha from statistical calculator: &quot;<br>    &lt;&lt;sum&lt;&lt;std::endl;<br>  GetSumV ( image, image, sum ) ;<br>  std::cout&lt;&lt;&quot;sum of temp.mha from volume calculator: &quot;<br>    &lt;&lt;sum&lt;&lt;std::endl;<br>  GetSumS ( image1, image1, sum ) ;<br>  std::cout&lt;&lt;&quot;sum of temp1.mha from statistical calculator: &quot;<br>    &lt;&lt;sum&lt;&lt;std::endl;<br>  GetSumV ( image1, image1, sum ) ;<br>  std::cout&lt;&lt;&quot;sum of temp1.mha from volume calculator: &quot;<br>    &lt;&lt;sum&lt;&lt;std::endl;<br>  }<br><br><br>int main(int argc, char **argv)<br>  {<br><br>  GetOverlappingSum ( ) ;<br><br>  return 1 ;<br>  }<br><!-- footer --><br><br><br><br><br><div style="border-bottom:1px solid #999"></div><br>

        <font color="black" style="font-size:14.8px">你 不 想 试 试 今 夏 最 “酷” 的 邮 箱 吗 ?</font>
        <br>
         <a href="http://www.126.com/" target="_blank" style="font-size:13px;line-height:160%;color:blue">蕴 涵 中 华 传 统 文 化 于 世 界 一 流 科 技 之 中,创 新 Ajax 技 术,126 “D 计 划”火 热 体 验 中 !
</a>