[Insight-users] ITK in python and C++

Luis Ibanez luis.ibanez at kitware.com
Tue Jul 14 13:22:58 EDT 2009


Hi Kevin,

                                 What is your Platform ?

You could do a quick test:

Attempt to allocate two arrays of 2GB each in your python interpreter.


For example:


import array
mega = 1024 * 1024
N = 500
a = array.array('B', [0] * N * mega )


and see how far you can get with N ....


In my Linux Ubuntu, with 4Gb ram and Python 2.5.2
I got up to 500 Mb, an the system monitor matches
the allocated memory for the python process to

On a Windows 64 bits machine with Windows Vista
and Python 2.5 (Windows installation), I got up to
300 Mb, and the Task manager indicated that the
python process was using 300 Mb.


There are probably much better ways of testing the
memory limits...


--------------

About your registration, what file format are you
using for writing the output ?


      Luis



---------------------------------------------------------------------------------------------------------------
On Mon, Jul 13, 2009 at 8:45 AM, kevin cavin <beibeiwen2003 at yahoo.com>wrote:

> 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
>
>
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090714/97f1eaf2/attachment-0001.htm>


More information about the Insight-users mailing list