c++ - Error when run Affine Transformation in Example Code." -


i downloaded affinetranformation form wiki example , modify affine 2 dicom files. build successfully. when run it. have error messenger:

terminate called after throwing instance of 'itk::exceptionobject'   what():  /usr/local/include/itk-4.4/itkimagefilewriter.hxx:123: itk::error: imagefilewriter(0x9808fd8): no filename specified aborted (core dumped) 

this editing code. please me edit it. using itk version newest 4.3.1 linux

  #include "itkcastimagefilter.h"`` #include "itkellipsespatialobject.h" #include "itkimage.h" #include "itkimageregistrationmethod.h" #include "itklinearinterpolateimagefunction.h" #include "itkimagefilereader.h" #include "itkimagefilewriter.h" #include "itkmeansquaresimagetoimagemetric.h" #include "itkregularstepgradientdescentoptimizer.h" #include "itkresampleimagefilter.h" #include "itkrescaleintensityimagefilter.h" #include "itkspatialobjecttoimagefilter.h" #include "itkaffinetransform.h" #include "itkgdcmimageio.h" // software guide : endcodesnippet #include <list> #include <fstream> const    unsigned int    dimension = 2; typedef  unsigned char           pixeltype;  typedef itk::image< pixeltype, dimension >  imagetype;  static void createellipseimage(imagetype::pointer image); static void createsphereimage(imagetype::pointer image);  int main(int, char *[] ) {   //  transform map fixed image moving image.   typedef itk::affinetransform< double, dimension > transformtype;    //  optimizer required explore parameter space of transform   //  in search of optimal values of metric.   typedef itk::regularstepgradientdescentoptimizer       optimizertype;    //  metric compare how 2 images match each other. metric   //  types parameterized image types can seen in   //  following type declaration.   typedef itk::meansquaresimagetoimagemetric<       imagetype,       imagetype >    metrictype;    //  finally, type of interpolator declared. interpolator   //  evaluate intensities of moving image @ non-grid positions.   typedef itk:: linearinterpolateimagefunction<       imagetype,       double          >    interpolatortype;       //  registration method type instantiated using types of   //  fixed , moving images. class responsible interconnecting   //  components have described far.   typedef itk::imageregistrationmethod<       imagetype,       imagetype >    registrationtype;       // create components   metrictype::pointer         metric        = metrictype::new();   transformtype::pointer      transform     = transformtype::new();   optimizertype::pointer      optimizer     = optimizertype::new();   interpolatortype::pointer   interpolator  = interpolatortype::new();   registrationtype::pointer   registration  = registrationtype::new();    // each component connected instance of registration method.   registration->setmetric(        metric        );   registration->setoptimizer(     optimizer     );   registration->settransform(     transform     );   registration->setinterpolator(  interpolator  );    // write 2 synthetic inputs    typedef itk::image< pixeltype, dimension >  fixedimagetype;   typedef itk::image< pixeltype, dimension >  movingimagetype;   // software guide : endcodesnippet   // set file readers   typedef itk::imagefilereader< fixedimagetype  > fixedimagereadertype;   typedef itk::imagefilereader< movingimagetype > movingimagereadertype;     fixedimagereadertype::pointer fixedimagereader   = fixedimagereadertype::new();    movingimagereadertype::pointer movingimagereader = movingimagereadertype::new();      fixedimagereader->setfilename("fix.dcm" );     movingimagereader->setfilename( "mov.dcm" );    typedef itk::imagefilewriter< imagetype >  writertype;    writertype::pointer      fixedwriter =  writertype::new();   //ixedwriter->setfilename("fixed.png");   fixedwriter->setinput( fixedimagereader->getoutput());   fixedwriter->update();    writertype::pointer      movingwriter =  writertype::new(); // movingwriter->setfilename("moving.png");   movingwriter->setinput( movingimagereader->getoutput());   movingwriter->update();    // set registration inputs   registration->setfixedimage(fixedimagereader->getoutput());   registration->setmovingimage(movingimagereader->getoutput());    registration->setfixedimageregion(     fixedimagereader->getoutput()->getlargestpossibleregion() );    //  initialize transform   typedef registrationtype::parameterstype parameterstype;   parameterstype initialparameters( transform->getnumberofparameters() );    // rotation matrix   initialparameters[0] = 1.0;  // r(0,0)   initialparameters[1] = 0.0;  // r(0,1)   initialparameters[2] = 0.0;  // r(1,0)   initialparameters[3] = 1.0;  // r(1,1)    // translation vector   initialparameters[4] = 0.0;   initialparameters[5] = 0.0;  registration->setinitialtransformparameters( initialparameters );    optimizer->setmaximumsteplength( .1 ); // if set high,   //"itk::error: meansquaresimagetoimagemetric(0xa27ce70): many samples map outside moving image buffer: 1818 / 10000" error    optimizer->setminimumsteplength( 0.01 );    // set stopping criterion   optimizer->setnumberofiterations( 200 );    // connect observer   //commanditerationupdate::pointer observer = commanditerationupdate::new();   //optimizer->addobserver( itk::iterationevent(), observer );    try   {     registration->update();   }   catch( itk::exceptionobject & err )   {     std::cerr << "exceptionobject caught !" << std::endl;     std::cerr << err << std::endl;     return exit_failure;   }   //  result of registration process array of parameters   //  defines spatial transformation in unique way. final result   //  obtained using \code{getlasttransformparameters()} method.    parameterstype finalparameters = registration->getlasttransformparameters();   std::cout << "final parameters: " << finalparameters << std::endl;    //  value of image metric corresponding last set of parameters   //  can obtained \code{getvalue()} method of optimizer.    const double bestvalue = optimizer->getvalue();    // print out results   //   std::cout << "result = " << std::endl;   std::cout << " metric value  = " << bestvalue          << std::endl;    //  common, last step of registration task, use   //  resulting transform map moving image fixed image space.   //  done \doxygen{resampleimagefilter}.    typedef itk::resampleimagefilter<       imagetype,       imagetype >    resamplefiltertype;    resamplefiltertype::pointer resampler = resamplefiltertype::new();   resampler->setinput( movingimagereader->getoutput());    //  transform produced output of registration method   //  passed input resampling filter. note use of   //  methods \code{getoutput()} , \code{get()}. combination needed   //  here because registration method acts filter output   //  transform decorated in form of \doxygen{dataobject}. details in   //  construction may want read documentation of   //  \doxygen{dataobjectdecorator}.    resampler->settransform( registration->getoutput()->get() );    //  described in section \ref{sec:resampleimagefilter},   //  resampleimagefilter requires additional parameters specified, in   //  particular, spacing, origin , size of output image. default   //  pixel value set distinct gray level in order highlight   //  regions mapped outside of moving image.    resampler->setsize( fixedimagereader->getoutput()->getlargestpossibleregion().getsize() );   resampler->setoutputorigin(  fixedimagereader->getoutput()->getorigin() );   resampler->setoutputspacing( fixedimagereader->getoutput()->getspacing() );   resampler->setoutputdirection( fixedimagereader->getoutput()->getdirection() );  resampler->setdefaultpixelvalue( 100 );    //  output of filter passed writer store   //  image in file. \doxygen{castimagefilter} used convert   //  pixel type of resampled image final type used   //  writer. cast , writer filters instantiated below.    typedef unsigned char outputpixeltype;   typedef itk::image< outputpixeltype, dimension > outputimagetype;   typedef itk::castimagefilter<       imagetype,       imagetype > castfiltertype;    writertype::pointer      writer =  writertype::new();   castfiltertype::pointer  caster =  castfiltertype::new();   writer->setfilename("output.png");   caster->setinput( resampler->getoutput() );   writer->setinput( caster->getoutput()   );   writer->update();     return exit_success; } 

the error message no filename specified , indeed calls setfilename() have been commented out:

  writertype::pointer      fixedwriter =  writertype::new();   // fixedwriter->setfilename("fixed.png");    writertype::pointer      movingwriter =  writertype::new();   // movingwriter->setfilename("moving.png"); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -