[Insight-users] Unhandled exception in .exe(KERNEL32.DLL) when castimagefilter update is called

sindhura sindhura at comsols.com
Tue Jun 21 01:03:04 EDT 2005


Hi Friends,

               When I was trying to call Update() on castimagefilter Iam getting unhandled exception.Even though I was using try-catch I was unable to caught the exception.
If anybody know the solution please help me.



memcpy(Buffer1,Buffer,img_size);
typedef float AccumulatorPixelType;
 const unsigned int Dimension = 2;
 
 typedef itk::Image< unsigned char, Dimension > ImageType;
 
 typedef itk::Image< AccumulatorPixelType, 2 > AccumulatorImageType;
 AccumulatorImageType::Pointer apointer = AccumulatorImageType::New();
 typedef ImageType::Pointer ImagePointer;
 
 //BufferToImageConversion
 ImagePointer image = ImageType::New();   
   
 int SizeArray[3] = {width, height, height};
 double spacing[3] = {voxelWidth, voxelHeight,voxelDepth};
 
 ImageType::SizeType size ;
 for (int i=0;i<Dimension;i++)
 {
  size[i] = SizeArray[i]; 
 }    
   
 ImageType::IndexType index ;
 index.Fill(0);
   
 ImageType::RegionType inregion;
 inregion.SetSize(size);
 inregion.SetIndex(index);
   
 image ->SetLargestPossibleRegion( inregion );
 image ->SetBufferedRegion( inregion );
 image ->SetRequestedRegion( inregion );
 image ->SetSpacing(spacing);
 image ->Allocate();
 
 itk::ImageRegionIteratorWithIndex<ImageType> it(image , inregion);
 int k=0;
 while( !it.IsAtEnd()) 
 {    
  it.Set(Buffer1[k]);
  k++;
  ++it;
 }//End Of BufferToImageConversion

 
 typedef itk::CastImageFilter<ImageType,AccumulatorImageType>CastingFilterType;
 CastingFilterType::Pointer caster = CastingFilterType::New();
 typedef itk::GradientMagnitudeImageFilter<AccumulatorImageType,AccumulatorImageType>GradientFilter;
 GradientFilter::Pointer gradFilter = GradientFilter::New();

 caster->SetInput(image);
 try {
    caster->UpdateLargestPossibleRegion();
  } 
 catch ( itk::ExceptionObject & err ) 
 {
      cout<<"ExceptionObject caught";
      cout<<err.GetDescription();
  }

 gradFilter->SetInput(caster->GetOutput());
 gradFilter->Update();

 typedef itk::ThresholdImageFilter<AccumulatorImageType>ThresholdFilterType;
  ThresholdFilterType::Pointer threshFilter = ThresholdFilterType::New();
 threshFilter->SetInput(gradFilter->GetOutput());
 threshFilter->SetOutsideValue(0);
 threshFilter->ThresholdOutside(ThreshMin,ThreshMax);
 threshFilter->Update();
 
 //HoughTransformation
 typedef itk::HoughTransform2DCirclesImageFilter<AccumulatorPixelType ,AccumulatorPixelType> HoughTransformFilterType;
 HoughTransformFilterType::Pointer houghFilter = HoughTransformFilterType::New();
 
 houghFilter->SetInput(threshFilter->GetOutput());
 houghFilter->SetNumberOfCircles( NoOfCircles );
 houghFilter->SetMinimumRadius( MinRadius );
 houghFilter->SetMaximumRadius( MaxRadius );
 houghFilter->SetSweepAngle(m_SweepAngle);
 houghFilter->SetSigmaGradient(m_SigmaGradient);
 houghFilter->SetVariance(m_Variance);
 //houghFilter->SetThreshold(0);
 houghFilter->SetDiscRadiusRatio(m_DiscRadiusRatio);
 houghFilter->Update();

 HoughTransformFilterType::CirclesListType circles;
 circles = houghFilter->GetCircles();
 typedef itk::Image< unsigned char, Dimension > OutputImageType;
 OutputImageType::Pointer localOutputImage = OutputImageType::New();
 OutputImageType::IndexType localIndex;
 OutputImageType::RegionType region;
 region.SetSize(image->GetLargestPossibleRegion().GetSize());
 region.SetIndex(image->GetLargestPossibleRegion().GetIndex());
 localOutputImage->SetRegions( region );
 localOutputImage->SetOrigin(image->GetOrigin());
 localOutputImage->SetSpacing(image->GetSpacing());
 localOutputImage->Allocate();
 localOutputImage->FillBuffer(0);

 typedef HoughTransformFilterType::CirclesListType CirclesListType;
 CirclesListType::const_iterator itCircles = circles.begin();

 while( itCircles != circles.end() )
 {
 
  for(double angle = 0;angle <= 2*vnl_math::pi; angle += vnl_math::pi/60.0 )
  {

  localIndex[0] = (long int)((*itCircles)->GetObjectToParentTransform()->GetOffset()[0]);
      //+ (*itCircles)->GetRadius()[0]*cos(angle));
  localIndex[1] = (long int)((*itCircles)->GetObjectToParentTransform()->GetOffset()[1]);
      //+ (*itCircles)->GetRadius()[0]*sin(angle));
  OutputImageType::RegionType region = localOutputImage->GetLargestPossibleRegion();

  if( region.IsInside( localIndex ) )
   {
   localOutputImage->SetPixel( localIndex, 255 );
   }
  }
 itCircles++;
 }

 OutBuffer = localOutputImage->GetBufferPointer();//end of houghtransformation
 for(int k=0;k<65536;k++)
  if(OutBuffer[k]!=0)
   OutBuffer[k]=255;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050621/c9f30a2e/attachment.html


More information about the Insight-users mailing list