Hello all,<br><br>I'd like to compute the mean and standard deviation of a part of an image. <br>That part is described by an ImageMaskSpatialObject.<br><br>The following program is what I came up with, but it behaves strangely. <br>the output is<br><br>Sample mean = [-1.#IND]<br>Sample covariance = -0<br><br>I think probably something wrong with the iterator, because<br>m_NumberOfPixels: 0<br><br>Also, the calculator worked fine if I use a ellipse as an input.<br><br>Any help/ideas are much appreciated, here is my code, the data is available at http://www.duke.edu/~kurtzhao/data.zip:<br><br>int TestSampler( ) <br> {<br> typedef double PixelType ;<br> typedef unsigned char OverlayPixelType ;<br> typedef itk::Image < PixelType, 3 > ImageType;<br> typedef itk::Image < OverlayPixelType, 3 > OverlayType;<br><br> typedef itk::ImageFileReader < ImageType > ImageReaderType;<br> ImageReaderType::Pointer imageReader = ImageReaderType::New();<br> imageReader -> SetFileName( "image.mhd" ) ;<br> try<br> {<br> imageReader -> Update();<br> }<br> catch( ... )<br> {<br> std::cout << "Problems reading image file " << <br> imageReader-> GetFileName ( ) << std::endl;<br> return EXIT_FAILURE ;<br> }<br><br> typedef itk::ImageFileReader < OverlayType > OverlayReaderType;<br> OverlayReaderType::Pointer overlayReader = OverlayReaderType::New();<br> overlayReader -> SetFileName( "overlay.mhd" ) ;<br> try<br> {<br> overlayReader -> Update();<br> }<br> catch( ... )<br> {<br> std::cout << "Problems reading overlay file " << <br> overlayReader-> GetFileName ( ) << std::endl;<br> return EXIT_FAILURE;<br> }<br> <br> ImageType::Pointer image = imageReader -> GetOutput ( ) ;<br><br> OverlayType::Pointer overlay = overlayReader -> GetOutput ( ) ;<br><br> ImageType::IndexType indexInside ;<br> indexInside [ 0 ] = 140 ;<br> indexInside [ 1 ] = 122 ;<br> indexInside [ 2 ] = 24 ;<br><br> typedef itk::ImageMaskSpatialObject<3> ImageMaskSpatialObject;<br> ImageMaskSpatialObject::Pointer maskSO = ImageMaskSpatialObject::New();<br> maskSO->SetImage( overlay );<br> //maskSO -> Print ( std::cout ) ;<br> ImageMaskSpatialObject::PointType inside ;<br> ImageMaskSpatialObject::PointType outside ;<br> for ( int i = 0 ; i < 3 ; i ++)<br> {<br> inside [ i ] = indexInside [ i ] * <br> image -> GetSpacing ( ) [ i ] ;<br> } <br> outside [ 0 ] = 197 ;<br> outside [ 1 ] = 65 ;<br> outside [ 2 ] = 14 ;<br> std::cout << "Is my point " << indexInside << " inside my mask image? "<br> << (int ) overlay -> GetPixel ( indexInside ) << std::endl;<br> std::cout << "Is my point " << inside << " inside my mask? "<br> << maskSO->IsInside(inside) << std::endl;<br> std::cout << "Is my point " << outside << " outside my mask? "<br> << !maskSO->IsInside(outside) << std::endl;<br><br><br> typedef itk::SpatialObjectToImageStatisticsCalculator< <br> ImageType, ImageMaskSpatialObject> CalculatorType;<br> CalculatorType::Pointer calculator = CalculatorType::New();<br> calculator->SetImage(image);<br> calculator->SetSpatialObject( maskSO );<br> calculator->Update();<br> calculator->Print ( std::cout );<br> std::cout << "Sample mean = " << calculator->GetMean() << std::endl ;<br> std::cout << "Sample covariance = " << calculator->GetCovarianceMatrix();<br> return EXIT_SUCCESS ;<br> }<br>int main(int argc, char **argv)<br> {<br> //itkEllipseBoundaryToImageFilterTest ( ) ;<br> TestSampler ( ) ;<br><br> return 1 ;<br> }<br><br>Best Regards<br>Kurt Zhao<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>