[Insight-users] an issue with SpatialObjectToImageStatist icsCalculator and ImageMaskSpatialObject.

Julien Jomier julien.jomier at kitware.com
Thu Jul 13 02:44:12 EDT 2006


Hi Kurt,

Thanks for the report.
The problem was that the MaskImageSpatialObject can be sparse, therefore
the Flood Filled iterator could not work in this case. I've put a fix in
the cvs repository.

Let me know if you still have any issues with this calculator,

Julien

kurt wrote:
> Hello all,
> 
> I'd like to compute the mean and standard deviation of a part of an image.
> That part is described by an ImageMaskSpatialObject.
> 
> The following program is what I came up with, but it behaves strangely.
> the output is
> 
> Sample mean = [-1.#IND]
> Sample covariance = -0
> 
> I think probably something wrong with the iterator, because
> m_NumberOfPixels: 0
> 
> Also, the calculator worked fine if I use a ellipse as an input.
> 
> Any help/ideas are much appreciated, here is my code, the data is 
> available at http://www.duke.edu/~kurtzhao/data.zip:
> 
> int TestSampler( )
> {
> typedef double PixelType ;
> typedef unsigned char OverlayPixelType ;
> typedef itk::Image < PixelType, 3 > ImageType;
> typedef itk::Image < OverlayPixelType, 3 > OverlayType;
> 
> typedef itk::ImageFileReader < ImageType > ImageReaderType;
> ImageReaderType::Pointer imageReader = ImageReaderType::New();
> imageReader -> SetFileName( "image.mhd" ) ;
> try
> {
> imageReader -> Update();
> }
> catch( ... )
> {
> std::cout << "Problems reading image file " <<
> imageReader-> GetFileName ( ) << std::endl;
> return EXIT_FAILURE ;
> }
> 
> typedef itk::ImageFileReader < OverlayType > OverlayReaderType;
> OverlayReaderType::Pointer overlayReader = OverlayReaderType::New();
> overlayReader -> SetFileName( "overlay.mhd" ) ;
> try
> {
> overlayReader -> Update();
> }
> catch( ... )
> {
> std::cout << "Problems reading overlay file " <<
> overlayReader-> GetFileName ( ) << std::endl;
> return EXIT_FAILURE;
> }
> 
> ImageType::Pointer image = imageReader -> GetOutput ( ) ;
> 
> OverlayType::Pointer overlay = overlayReader -> GetOutput ( ) ;
> 
> ImageType::IndexType indexInside ;
> indexInside [ 0 ] = 140 ;
> indexInside [ 1 ] = 122 ;
> indexInside [ 2 ] = 24 ;
> 
> typedef itk::ImageMaskSpatialObject<3> ImageMaskSpatialObject;
> ImageMaskSpatialObject::Pointer maskSO = ImageMaskSpatialObject::New();
> maskSO->SetImage( overlay );
> //maskSO -> Print ( std::cout ) ;
> ImageMaskSpatialObject::PointType inside ;
> ImageMaskSpatialObject::PointType outside ;
> for ( int i = 0 ; i < 3 ; i ++)
> {
> inside [ i ] = indexInside [ i ] *
> image -> GetSpacing ( ) [ i ] ;
> }
> outside [ 0 ] = 197 ;
> outside [ 1 ] = 65 ;
> outside [ 2 ] = 14 ;
> std::cout << "Is my point " << indexInside << " inside my mask image? "
> << (int ) overlay -> GetPixel ( indexInside ) << std::endl;
> std::cout << "Is my point " << inside << " inside my mask? "
> << maskSO->IsInside(inside) << std::endl;
> std::cout << "Is my point " << outside << " outside my mask? "
> << !maskSO->IsInside(outside) << std::endl;
> 
> 
> typedef itk::SpatialObjectToImageStatisticsCalculator<
> ImageType, ImageMaskSpatialObject> CalculatorType;
> CalculatorType::Pointer calculator = CalculatorType::New();
> calculator->SetImage(image);
> calculator->SetSpatialObject( maskSO );
> calculator->Update();
> calculator->Print ( std::cout );
> std::cout << "Sample mean = " << calculator->GetMean() << std::endl ;
> std::cout << "Sample covariance = " << calculator->GetCovarianceMatrix();
> return EXIT_SUCCESS ;
> }
> int main(int argc, char **argv)
> {
> //itkEllipseBoundaryToImageFilterTest ( ) ;
> TestSampler ( ) ;
> 
> return 1 ;
> }
> 
> Best Regards
> Kurt Zhao
> 
> 
> 
> 
> 
> 
> 你 不 想 试 试 今 夏 最 “酷” 的 邮 箱 吗 ?
> 蕴 涵 中 华 传 统 文 化 于 世 界 一 流 科 技 之 中,创 新 Ajax 技 术, 
> 126 “D 计 划”火 热 体 验 中 ! <http://www.126.com/>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list