[Insight-users] One error and one issue with itkImagePCAShapeModelEstimator

Zachary Pincus zpincus@stanford.edu
Fri May 14 00:26:05 EDT 2004


--Apple-Mail-4-956866627
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Luis,

(1) I'll put together a patch for this later tonight. I've got it 
working already, but it's a bit of a mess. One question: in the 
GenerateInputRequestedRegion method, of an ImageToImageFilter subclass, 
MUST Superclass::GenerateInputRequestedRegion be called?

Calling it causes some problems that I have to undo later in the 
PCAShapeModelEstimator's implementation of that method. If It needn't 
be called, great. If however, some bookkeeping gets done somewhere up 
the chain, I'll keep the call in there and just fix the damage.

(2) No offense about the compiler bugs for gcc/darwin/ppc -- it's being 
modified at a rapid rate, and we all know what that does for the bug 
count.

Anyhow, I just recompiled a recent CVS checkout of ITK (from scratch in 
a new directory, on a new machine with a fresh dev tools install, no 
less...) with static libraries and ran my test code again. (code 
attached) Again, the exception is not caught. However, the backtrace is 
less broken. (included below).

Interestingly enough, if I comment out lines 145 and 146 of 
itkImagePCAShapeModelEstimator.txx, then an exception gets raised -- 
and caught properly -- in some code elsewhere.
If I fix this problem by further commenting out lines 121 and 151 (see 
1 above), the test runs properly.
If I try to throw an exception elsewhere in the "negotiation" code 
(GenerateInputRequestedRegion, EnlargeOutputRequestedRegion), the 
exception is not caught. If I try to throw an exception elsewhere in 
the code (e.g. GenerateData), this exception gets caught properly.

Strange. Does the provided test code work right on other platforms?

Zach


--Apple-Mail-4-956866627
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="pcatest.cxx"
Content-Disposition: attachment;
	filename=pcatest.cxx

// Insight classes
#include "itkImage.h"
#include "itkImageRegionIterator.h"

#include "itkImagePCAShapeModelEstimator.h"

//Data definitions 
#define   IMGWIDTH            2
#define   IMGHEIGHT           2
#define   NDIMENSION          2
#define   NUMTRAINIMAGES      3
#define   NUMLARGESTPC        2


int main(int, char* [] )
{

  //------------------------------------------------------
  //Create 3 simple test images with
  //------------------------------------------------------
  typedef itk::Image<double,NDIMENSION> InputImageType; 
  typedef itk::Image<double,NDIMENSION> OutputImageType; 
  typedef itk::Image<double,NDIMENSION> MeanImageType;


  typedef InputImageType::PixelType ImagePixelType;

  typedef InputImageType::PixelType InputImagePixelType;

  typedef
    itk::ImageRegionIterator< InputImageType > InputImageIterator;

  typedef
    itk::ImageRegionIterator< OutputImageType > OutputImageIterator;
  
  InputImageType::Pointer image1 = InputImageType::New();

  InputImageType::Pointer image2 = InputImageType::New();

  InputImageType::Pointer image3 = InputImageType::New();

  InputImageType::SizeType inputImageSize = {{ IMGWIDTH, IMGHEIGHT }};

  InputImageType::IndexType index, index2;
  index.Fill(0);
  index2.Fill(100);
  InputImageType::RegionType region, region2;

  region.SetSize( inputImageSize );
  region.SetIndex( index2);
  region2.SetSize(inputImageSize);
  region2.SetIndex(index);

  //--------------------------------------------------------------------------
  // Set up Image 1 first
  //--------------------------------------------------------------------------

  image1->SetRegions( region );
  image1->Allocate();

  // setup the iterators
  InputImageIterator image1It( image1, image1->GetBufferedRegion() );

  //--------------------------------------------------------------------------
  // Set up Image 2 first
  //--------------------------------------------------------------------------

  image2->SetRegions( region );
  image2->Allocate();

  // setup the iterators
  InputImageIterator image2It( image2, image2->GetBufferedRegion() );

  //--------------------------------------------------------------------------
  // Set up Image 3 first
  //--------------------------------------------------------------------------

  image3->SetRegions( region2 );
  image3->Allocate();

  // setup the iterators
  InputImageIterator image3It( image3, image3->GetBufferedRegion() );

  //--------------------------------------------------------------------------
  //Manually create and store each vector
  //--------------------------------------------------------------------------
  //Image no. 1
  for( int i = 0; i< 4; i++ )
    {
    image1It.Set( 1 ); ++image1It;
    }
  //Image no. 2
  image2It.Set( 2 ); ++image2It;
  image2It.Set( 0 ); ++image2It;
  image2It.Set( 0 ); ++image2It;
  image2It.Set( 2 ); ++image2It;

  //Image no. 3
  image3It.Set( 0 ); ++image3It;
  image3It.Set( 3 ); ++image3It;
  image3It.Set( 3 ); ++image3It;
  image3It.Set( 0 ); ++image3It;

  //----------------------------------------------------------------------
  // Test code for the Shape model estimator
  //----------------------------------------------------------------------

  //----------------------------------------------------------------------
  //Set the image model estimator
  //----------------------------------------------------------------------
  typedef itk::ImagePCAShapeModelEstimator<InputImageType, OutputImageType> 
    ImagePCAShapeModelEstimatorType;

  ImagePCAShapeModelEstimatorType::Pointer 
    applyPCAShapeEstimator = ImagePCAShapeModelEstimatorType::New();

  //----------------------------------------------------------------------
  //Set the parameters of the clusterer
  //----------------------------------------------------------------------
  try {
	  
  applyPCAShapeEstimator->SetNumberOfTrainingImages( NUMTRAINIMAGES );
  applyPCAShapeEstimator->SetNumberOfPrincipalComponentsRequired( NUMLARGESTPC );
  
  applyPCAShapeEstimator->SetInput(0, image1);
  applyPCAShapeEstimator->SetInput(1, image2);
  applyPCAShapeEstimator->SetInput(2, image3);
 
  applyPCAShapeEstimator->Update();

  } catch( itk::ExceptionObject & err ) { 
	  std::cout << "ExceptionObject caught !" << std::endl; 
	  std::cout << err << std::endl; 
	  return -1;
  }

  return 0;
}


--Apple-Mail-4-956866627
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed


Backtrace for provided code:
(gdb) run
Starting program: /Users/zpincus/Developer/Code/PCACalc/pcatest
Reading symbols for shared libraries . done

Program received signal SIGABRT, Aborted.
0x90042aac in kill ()
(gdb) where
#0  0x90042aac in kill ()
#1  0x9009ec5c in abort ()
#2  0x000843e4 in __cxxabiv1::__terminate(void (*)()) () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#3  0x00084428 in std::terminate() () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#4  0x00084440 in __cxxabiv1::__unexpected(void (*)()) () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#5  0x0005a5c4 in __cxa_call_unexpected () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#6  0x0000590c in itk::DataObject::PropagateRequestedRegion() () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#7  0x000054a0 in itk::DataObject::Update() () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#8  0x0000a9c0 in itk::ProcessObject::Update() () at 
/Users/zpincus/Developer/ITK-CVS-src/Insight/Code/Common/itkImage.h:89
#9  0x00003258 in main () at 
/Users/zpincus/Developer/Code/PCACalc/pcatest.cxx:129




On May 13, 2004, at 12:59 PM, Luis Ibanez wrote:

>
> Hi Zach,
>
>
>
> 1) It seems reasonable to allow the ImagePCAShapeModelEstimator
>    to accept images of different origin, different StartIndex
>    and only enforce the pixel spacing and the image size (in
>    pixel along every dimension) to be the same among all the
>    input images.
>
>    Please send us a patch...
>
>
>
> 2) It is strange what you report regarding the exception...
>
>    It may look like a missmatch between the version of your
>    compiler and the version of the debugger...
>
>    No offense, ... but the Mac have proven to have many
>    compiler bugs in the past...
>
>
>    Just out of curiosity: Have you tried this same test
>    by builng ITK in static libraries ?
>
>
>
> Regards,
>
>
>
>     Luis
>
>
> ---------------------
> Zachary Pincus wrote:
>
>> Hello,
>> I've run into a problematic situation: I want to estimate a PCA model 
>>  of several regions (same size) from the same image. I just run an  
>> ExtractImageFilter a few times to get a bunch of sub-images, and feed 
>>  them to the model estimator. This should be no problem, but:
>> (1) itk::ImagePCAShapeModelEstimator will not accept images with  
>> different LargestPossibleRegions, regardless of whether they are the  
>> same size. This seems unnecessarily restrictive to me. If others 
>> agree,  I'll happily submit a patch to remedy this behavior.
>> The more problematic thing is that I had a really hard time tracking  
>> down this bug because:
>> (2) Somehow the exception reporting from this class seems to be 
>> broken.  I'm not sure if it's just me, but even though I've got a 
>> try/catch  block, I can't catch the exception raised by an  
>> ImagePCAShapeModelEstimator object when you try to feed it 
>> wrong-sized  images. This exception is raised on line 146 of  
>> itkImagePCAShapeModelEstimator.txx -- I know this because when I put 
>> a  bunch of printfs (well, std::cout <<, but you get my drift) in the 
>>  template code, I get output right up until where the exception is to 
>> be  called. Somehow, the exception doesn't get propagated back 
>> properly.
>> I've included some stripped-down test code (derived from the test 
>> code  in the ITK tree) that on my machine reproduces this problem. 
>> The code  tries to feed an ImagePCAShapeModelEstimator images with 
>> different  regions (though the sizes are the same). All of this is 
>> done within a  try/catch block; however the exception raised on line 
>> 146 of  itkImagePCAShapeModelEstimator.txx never gets caught. (My 
>> setup: OS X  10.3.3, GCC 3.3 using c++ (not g++) compiler, with a CVS 
>> version of ITK  updated last night, built with shared libraries.)
>> Strange,
>> Zach Pincus
>> Attached is the test code. Here follows a backtrace of what I get 
>> when  I run it in GDB. There is some strangeness afoot even in the 
>> backtrace  -- note the "itkOctreeNode" source files erroneously 
>> assigned to  symbols from the standard c++ library.
>> #0  0x90042aac in kill ()
>> #1  0x9009ec5c in abort ()
>> #2  0x00018034 in __cxxabiv1::__terminate(void (*)()) () at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkSmartPointer.h:66
>> #3  0x00018078 in std::terminate() () at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkSmartPointer.h:66
>> #4  0x028079fc in __cxxabiv1::__unexpected(void (*)()) () at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkOctreeNode.h:117
>> #5  0x027f607c in __cxa_call_unexpected () at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkOctreeNode.h:117
>> #6  0x027d3e94 in itk::DataObject::PropagateRequestedRegion()  
>> (this=0x2501110) at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkDataObject.h:90
>> #7  0x027d3388 in itk::DataObject::Update() (this=0x25009e0) at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkDataObject.cxx:343
>> #8  0x0000343c in main () at  
>> /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/Common/ 
>> itkSmartPointer.h:71
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>

--Apple-Mail-4-956866627--




More information about the Insight-users mailing list