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

kurt kurtzhao at yeah.net
Wed Jul 12 09:39:26 EDT 2006


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060712/50deff12/attachment.html


More information about the Insight-users mailing list