[Insight-users] ITK in python and C++
kevin cavin
beibeiwen2003 at yahoo.com
Mon Jul 13 08:45:25 EDT 2009
Hi, guys:
When I use ITK respectively in C++ and Pyhton, with similar set up, (here I mean same registration method, metric, optimizer and interpolator), C++ version allow me register more slice than python version. It is quite strange for me. I can see from the taks manager that PF usage for C++ version can reach 2.89GB, but python version usually stay below 2GB. Does anyone has similar experinces?
In addition, I can get reasonable registration result in C++ version. BUT the program report Debug error when the application try to write the difference image into a file
the code like this
typedef itk::ResampleImageFilter<MovingImageType,
FixedImageType > ResampleFilterType;
TransformType::Pointer finalTransform = TransformType::New();
finalTransform->SetParameters( finalParameters );
ResampleFilterType::Pointer resample = ResampleFilterType::New();
resample->SetTransform( finalTransform );
resample->SetInput( intensityWindowing_moving->GetOutput() );
FixedImageType::Pointer fixedImage = intensityWindowing_fixed->GetOutput();
PixelType backgroundGrayLevel = 0;
if( argc > 4 )
{
backgroundGrayLevel = atoi( argv[4] );
}
resample->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
resample->SetOutputOrigin( fixedImage->GetOrigin() );
resample->SetOutputSpacing( fixedImage->GetSpacing() );
resample->SetOutputDirection( fixedImage->GetDirection() );
resample->SetDefaultPixelValue( backgroundGrayLevel );
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::CastImageFilter<
FixedImageType,
OutputImageType > CastFilterType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
CastFilterType::Pointer caster = CastFilterType::New();
WriterType::Pointer writer_diff = WriterType::New();
writer->SetFileName( argv[3] );
writer->SetImageIO( vtkIO );
caster->SetInput( resample->GetOutput() );
writer->SetInput( caster->GetOutput() );
writer->Update();
// Software Guide : BeginCodeSnippet
typedef itk::SubtractImageFilter<
FixedImageType,
FixedImageType,
FixedImageType > DifferenceFilterType;
DifferenceFilterType::Pointer difference = DifferenceFilterType::New();
typedef itk::RescaleIntensityImageFilter<
FixedImageType,
FixedImageType > RescalerType;
RescalerType::Pointer intensityRescaler = RescalerType::New();
// After registration
// resample->SetTransform( finalTransform );
difference->SetInput2( fixedImage );
difference->SetInput1( resample->GetOutput() );
intensityRescaler->SetInput( difference->GetOutput() );
intensityRescaler->SetOutputMinimum( 0 );
intensityRescaler->SetOutputMaximum( 255 );
caster->SetInput( intensityRescaler->GetOutput() );
writer_diff->SetImageIO( vtkIO );
writer_diff->SetInput( caster->GetOutput() );
// if( argc >5 )
{
writer_diff->SetFileName( argv[3] );
writer_diff->Update();
}
The resample use the final transformation to correct the moving image and the subtractImageFilter calculate the difference after registration. .
Thanks!
Wen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090713/9e1bf3b2/attachment.htm>
More information about the Insight-users
mailing list