[Insight-users] Obtain overlapping pixel volume

Luis Ibanez luis.ibanez at kitware.com
Sun Oct 22 19:02:33 EDT 2006


Hi Jonathan,

You are writing the GetOutput() method of the readers inside
the try/catch block and doing the Update() outside of it.


Instead of that, you should do the following:


      reader2->SetFileName( argv[ 2 ] );
      try
        {
        reader2->Update();
        }
      catch( itk::ExceptionObject & err )
        {
        std::cout << "ExceptionObject caught !" << std::endl;
        std::cout << err << std::endl;
        return -1;
        }
      image2=reader2->GetOutput();


Chances are that there is a real problem with reading your
moving image. With this new code you should see the exception
error that correspond to the (potential) problem with reading
the moving image.


    Regards,



       Luis



=======================
Jonathan Wong wrote:
> Thanks Luis.
> 
> However, I'm running into a problem with the ImageToImageMetric. I've 
> posted my code below. It seems to always throw an exception when the 
> ImagetoImageMetric tries to mMovingImage->GetSource(). However, the 
> fixedImage doesn't have this problem. I've even done GetSource before 
> the ImageToImageMetric and it has worked fine. I'm using ITK 2.8.1.
> 
> If you could point out how I should fix this that'd be great. Thanks
> 
> -Jonathan Wong.
> 
> Code:
> /*
> Overlap - This program attempts to calculuate the overlap between
> two binary segmented images. Specifically, it utilizes the
> Kappa Statistics Image metric
> */
> #include <iostream>
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkKappaStatisticImageToImageMetric.h"
> #include " itkNearestNeighborInterpolateImageFunction.h"
> #include "itkSimilarity3DTransform.h"
> 
> 
> int main( int argc, char *argv[] )
> {
>     // Declare the image type
>     typedef itk::Image<unsigned char, 3> ImageType;
>     // Declare imageReader
>     typedef itk::ImageFileReader<   ImageType >  ReaderType;
>     ReaderType::Pointer reader1 = ReaderType::New();
>     ReaderType::Pointer reader2 = ReaderType::New();
>     //set file name
>     reader1->SetFileName( argv[ 1 ] );
> 
>     ImageType::Pointer image1 = ImageType::New();
>     ImageType::Pointer image2= ImageType::New();
>     try
>     {
>         image1=reader1->GetOutput();
>        
>     }
>     catch( itk::ExceptionObject & err )
>     {
>         std::cout << "ExceptionObject caught !" << std::endl;
>         std::cout << err << std::endl;
>         return -1;
>     }
>     std::cout << argv[1] << " read successfully." << std::endl;
> 
>     //read in second image
>     reader2->SetFileName( argv[ 2 ] );
>     try
>     {
>        
>         image2=reader2->GetOutput();
>        
>     }
>     catch( itk::ExceptionObject & err )
>     {
>         std::cout << "ExceptionObject caught !" << std::endl;
>         std::cout << err << std::endl;
>         return -1;
>     }
> 
>     image1->Update();
>     image2->Update();
> 
>     std::cout << argv[2] << " read successfully." << std::endl;
>     std::cout << "Begin comparison." << std::endl;
> 
>     //define comparator
>     typedef itk::KappaStatisticImageToImageMetric <ImageType,ImageType> 
> MetricType;
>     MetricType::Pointer metric = MetricType::New();
> 
>     //define interpolator
>     typedef itk::NearestNeighborInterpolateImageFunction 
> <ImageType,double> InterpolatorType;
>     InterpolatorType::Pointer interpolator = InterpolatorType::New();
> 
>     //define transform
>     typedef itk::Similarity3DTransform <double> TransformType;
>     TransformType::Pointer transform = TransformType::New();
>     transform->SetIdentity(); //set as Identity
> 
>     TransformType::ParametersType parameters = transform->GetParameters();
> 
>     reader1->Update();
>     reader2->Update();
> 
>     metric -> SetFixedImage ( image1 );
>     metric -> SetMovingImage( image2 );
>     metric -> SetTransform ( transform );
>     metric -> SetTransformParameters(parameters);
>     metric -> SetInterpolator ( interpolator );
>     metric -> Initialize();
> 
> 
>     metric->Print(std::cout,0);
> 
> 
>     return 0;
> }
> 
> On 10/9/06, *Luis Ibanez* <luis.ibanez at kitware.com 
> <mailto:luis.ibanez at kitware.com>> wrote:
> 
> 
>     Hi Jonathan,
> 
>     ITK has a full set of filters for comparing segmentations.
> 
> 
>     You may want to use one or several of the following:
> 
>     KappaStatistics Metric:
>     http://www.itk.org/Insight/Doxygen/html/classitk_1_1KappaStatisticImageToImageMetric.html
>     <http://www.itk.org/Insight/Doxygen/html/classitk_1_1KappaStatisticImageToImageMetric.html>
> 
>     Match Cardinality:
>     http://www.itk.org/Insight/Doxygen/html/classitk_1_1MatchCardinalityImageToImageMetric.html
>     <http://www.itk.org/Insight/Doxygen/html/classitk_1_1MatchCardinalityImageToImageMetric.html>
> 
>     HausdorffDistanceImageFilter:
>     http://www.itk.org/Insight/Doxygen/html/classitk_1_1HausdorffDistanceImageFilter.html
>     <http://www.itk.org/Insight/Doxygen/html/classitk_1_1HausdorffDistanceImageFilter.html>
> 
>     ContourMeanDistanceImageFilter
>     http://www.itk.org/Insight/Doxygen/html/classitk_1_1ContourMeanDistanceImageFilter.html
>     <http://www.itk.org/Insight/Doxygen/html/classitk_1_1ContourMeanDistanceImageFilter.html>
> 
>     ContourDirectedMeanDistanceImageFilter
>     http://www.itk.org/Insight/Doxygen/html/classitk_1_1ContourDirectedMeanDistanceImageFilter.html
>     <http://www.itk.org/Insight/Doxygen/html/classitk_1_1ContourDirectedMeanDistanceImageFilter.html>
> 
> 
>     You may also want to try the program "Valmet" that was developed
>     at the University of North Carolina at Chapel Hill:
> 
>          http://www.ia.unc.edu/dev/download/valmet/index.htm
>     <http://www.ia.unc.edu/dev/download/valmet/index.htm>
> 
>     Unfortunately Valmet is not Open Source, but you can download
>     free binaries from the link above.
> 
> 
>          Regards,
> 
> 
>             Luis
> 
> 
>     =======================
>     Jonathan Wong wrote:
>      > Hi. The 3d images I have already are segmented and are therefore
>     binary.
>      > If i wanted to compare the the overlapping number of voxels how
>     would i
>      > do this? I've been looking around on the ITK mailing list and
>     someone
>      > has tried to use the SpatialObjecttoImageFilter, adding two images
>      > together and then counting the number of pixels with intensity 2, and
>      > used the LabelImageStatistics filter.
>      >
>      > The LabelImageStatistics filter does not work for me (it compiles
>     but
>      > the LabelImageStatisticsFilter Test fails), and I'm running it off of
>      > CVS. Also the SpatialObjectImageFilter and iterating through the
>     volume
>      > give me different results.
>      >
>      > I don't really know what the spatialObjectImageFilter does and would
>      > like to know how it works.
>      >
>      > Also what modifications would i have to make, if i were comparing
>     images
>      > of the same size, but different resolutions also pre-segmented to be
>      > binary?
>      >
>      > Thanks
>      > -Jonathan Wong
>      >
>      >
>      >
>     ------------------------------------------------------------------------
>      >
>      > _______________________________________________
>      > Insight-users mailing list
>      > Insight-users at itk.org <mailto:Insight-users at itk.org>
>      > http://www.itk.org/mailman/listinfo/insight-users
> 
> 
> 


More information about the Insight-users mailing list