<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Hi Friends,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2>
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.</FONT></DIV>
<DIV><FONT face=Arial size=2>If anybody know the solution please help
me.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>memcpy(Buffer1,Buffer,img_size);</FONT></DIV>
<DIV><FONT face=Arial size=2>typedef float AccumulatorPixelType;<BR> const
unsigned int Dimension = 2;<BR> <BR> typedef itk::Image< unsigned
char, Dimension > ImageType;<BR> <BR> typedef itk::Image<
AccumulatorPixelType, 2 >
AccumulatorImageType;<BR> AccumulatorImageType::Pointer apointer =
AccumulatorImageType::New();<BR> typedef ImageType::Pointer
ImagePointer;<BR> <BR> //BufferToImageConversion<BR> ImagePointer
image = ImageType::New(); <BR> <BR> int
SizeArray[3] = {width, height, height};<BR> double spacing[3] =
{voxelWidth, voxelHeight,voxelDepth};<BR> <BR> ImageType::SizeType
size ;<BR> for (int
i=0;i<Dimension;i++)<BR> {<BR> size[i] =
SizeArray[i]; <BR> } <BR> <BR> ImageType::IndexType
index
;<BR> index.Fill(0);<BR> <BR> ImageType::RegionType
inregion;<BR> inregion.SetSize(size);<BR> inregion.SetIndex(index);<BR> <BR> image
->SetLargestPossibleRegion( inregion );<BR> image
->SetBufferedRegion( inregion );<BR> image ->SetRequestedRegion(
inregion );<BR> image ->SetSpacing(spacing);<BR> image
->Allocate();<BR> <BR> itk::ImageRegionIteratorWithIndex<ImageType>
it(image , inregion);<BR> int k=0;<BR> while( !it.IsAtEnd())
<BR> {
<BR> it.Set(Buffer1[k]);<BR> k++;<BR> ++it;<BR> }//End
Of BufferToImageConversion</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> <BR> typedef
itk::CastImageFilter<ImageType,AccumulatorImageType>CastingFilterType;<BR> CastingFilterType::Pointer
caster = CastingFilterType::New();<BR> typedef
itk::GradientMagnitudeImageFilter<AccumulatorImageType,AccumulatorImageType>GradientFilter;<BR> GradientFilter::Pointer
gradFilter = GradientFilter::New();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> caster->SetInput(image);<BR> try
{<BR>
caster->UpdateLargestPossibleRegion();<BR> } <BR> catch (
itk::ExceptionObject & err ) <BR> {<BR>
cout<<"ExceptionObject caught";<BR>
cout<<err.GetDescription();<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2> gradFilter->SetInput(caster->GetOutput());<BR> gradFilter->Update();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> typedef
itk::ThresholdImageFilter<AccumulatorImageType>ThresholdFilterType;<BR> ThresholdFilterType::Pointer
threshFilter =
ThresholdFilterType::New();<BR> threshFilter->SetInput(gradFilter->GetOutput());<BR> threshFilter->SetOutsideValue(0);<BR> threshFilter->ThresholdOutside(ThreshMin,ThreshMax);<BR> threshFilter->Update();<BR> <BR> //HoughTransformation<BR> typedef
itk::HoughTransform2DCirclesImageFilter<AccumulatorPixelType
,AccumulatorPixelType>
HoughTransformFilterType;<BR> HoughTransformFilterType::Pointer houghFilter
=
HoughTransformFilterType::New();<BR> <BR> houghFilter->SetInput(threshFilter->GetOutput());<BR> houghFilter->SetNumberOfCircles(
NoOfCircles );<BR> houghFilter->SetMinimumRadius( MinRadius
);<BR> houghFilter->SetMaximumRadius( MaxRadius
);<BR> houghFilter->SetSweepAngle(m_SweepAngle);<BR> houghFilter->SetSigmaGradient(m_SigmaGradient);<BR> houghFilter->SetVariance(m_Variance);<BR> //houghFilter->SetThreshold(0);<BR> houghFilter->SetDiscRadiusRatio(m_DiscRadiusRatio);<BR> houghFilter->Update();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> HoughTransformFilterType::CirclesListType
circles;<BR> circles = houghFilter->GetCircles();<BR> typedef
itk::Image< unsigned char, Dimension >
OutputImageType;<BR> OutputImageType::Pointer localOutputImage =
OutputImageType::New();<BR> OutputImageType::IndexType
localIndex;<BR> OutputImageType::RegionType
region;<BR> region.SetSize(image->GetLargestPossibleRegion().GetSize());<BR> region.SetIndex(image->GetLargestPossibleRegion().GetIndex());<BR> localOutputImage->SetRegions(
region
);<BR> localOutputImage->SetOrigin(image->GetOrigin());<BR> localOutputImage->SetSpacing(image->GetSpacing());<BR> localOutputImage->Allocate();<BR> localOutputImage->FillBuffer(0);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> typedef
HoughTransformFilterType::CirclesListType
CirclesListType;<BR> CirclesListType::const_iterator itCircles =
circles.begin();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> while( itCircles != circles.end()
)<BR> {<BR> <BR> for(double angle = 0;angle <=
2*vnl_math::pi; angle += vnl_math::pi/60.0 )<BR> {</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> localIndex[0] = (long
int)((*itCircles)->GetObjectToParentTransform()->GetOffset()[0]);<BR> //+
(*itCircles)->GetRadius()[0]*cos(angle));<BR> localIndex[1] =
(long
int)((*itCircles)->GetObjectToParentTransform()->GetOffset()[1]);<BR> //+
(*itCircles)->GetRadius()[0]*sin(angle));<BR> OutputImageType::RegionType
region = localOutputImage->GetLargestPossibleRegion();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if( region.IsInside( localIndex )
)<BR> {<BR> localOutputImage->SetPixel(
localIndex, 255
);<BR> }<BR> }<BR> itCircles++;<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> OutBuffer =
localOutputImage->GetBufferPointer();//end of
houghtransformation<BR> for(int
k=0;k<65536;k++)<BR> if(OutBuffer[k]!=0)<BR> OutBuffer[k]=255;</FONT></DIV></BODY></HTML>