<div dir="ltr">Hi Matt,<div>I have added this code:</div><div>"</div><div><div>Image2->SetOrigin(Image1->GetOrigin());</div><div>  Image2->SetSpacing(Image1->GetSpacing());</div><div>  Image2->SetDirection(Image1->GetDirection());"</div></div><div>but the problem remain the same.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-28 0:10 GMT+02:00 Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Stefano,<br>
<br>
The means that the images must occupy the same spatial domain.  The<br>
domain is determined by the Origin, Spacing, Direction, and<br>
ImageRegion Size of the Image's.  This is explained more in the ITK<br>
Software Guide:<br>
<br>
  <a href="http://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch4.html#x40-430004" rel="noreferrer" target="_blank">http://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch4.html#x40-430004</a><br>
<br>
HTH,<br>
Matt<br>
<div><div class="h5"><br>
On Sun, Sep 27, 2015 at 5:56 PM, stefano serviddio<br>
<<a href="mailto:s.serviddio@gmail.com">s.serviddio@gmail.com</a>> wrote:<br>
> HI,<br>
> I have always the same issue with my demons registration code, "Inputs do<br>
> not occupy the same physical space".<br>
>  the fixed image is a Ct  512x512 dicom and the second one is a Pet  256x256<br>
> dicom.<br>
> May you help me to find out what is the problem?<br>
> Thank you very much.<br>
><br>
><br>
><br>
> #include "itkImageFileReader.h"<br>
> #include "itkImageFileWriter.h"<br>
> #include <time.h><br>
> #include <fstream><br>
> #include "itkSymmetricForcesDemonsRegistrationFilter.h"<br>
> #include "itkHistogramMatchingImageFilter.h"<br>
> #include "itkCastImageFilter.h"<br>
> #include "itkWarpImageFilter.h"<br>
><br>
> #include "itkGDCMImageIO.h"<br>
> #include "itkShrinkImageFilter.h"<br>
><br>
><br>
><br>
>   class CommandIterationUpdate : public itk::Command<br>
>   {<br>
>   public:<br>
>     typedef  CommandIterationUpdate                     Self;<br>
>     typedef  itk::Command                               Superclass;<br>
>     typedef  itk::SmartPointer<CommandIterationUpdate>  Pointer;<br>
>     itkNewMacro( CommandIterationUpdate );<br>
>   protected:<br>
>     CommandIterationUpdate() {};<br>
><br>
>     typedef itk::Image< double, 2 >            InternalImageType;<br>
>     typedef itk::Vector< double, 2 >           VectorPixelType;<br>
>     typedef itk::Image<  VectorPixelType, 2 > DisplacementFieldType;<br>
><br>
>     typedef itk::SymmetricForcesDemonsRegistrationFilter<<br>
>                                 InternalImageType,<br>
>                                 InternalImageType,<br>
>                                 DisplacementFieldType><br>
> RegistrationFilterType;<br>
><br>
>   public:<br>
><br>
>     void Execute(itk::Object *caller, const itk::EventObject & event)<br>
> ITK_OVERRIDE<br>
>       {<br>
>         Execute( (const itk::Object *)caller, event);<br>
>       }<br>
><br>
>     void Execute(const itk::Object * object, const itk::EventObject & event)<br>
> ITK_OVERRIDE<br>
>       {<br>
>          const RegistrationFilterType * filter = static_cast< const<br>
> RegistrationFilterType * >( object );<br>
>         if( !(itk::IterationEvent().CheckEvent( &event )) )<br>
>           {<br>
>           return;<br>
>           }<br>
>         std::cout << filter->GetMetric() << std::endl;<br>
>       }<br>
>   };<br>
><br>
><br>
> int main( int argc, char *argv[] )<br>
> {<br>
>   /*if( argc < 4 )<br>
>     {<br>
>     std::cerr << "Missing Parameters " << std::endl;<br>
>     std::cerr << "Usage: " << argv[0];<br>
>     std::cerr << " fixedImageFile movingImageFile ";<br>
>     std::cerr << " outputImageFile " << std::endl;<br>
>     std::cerr << " [outputDisplacementFieldFile] " << std::endl;<br>
>     return EXIT_FAILURE;<br>
>     }*/<br>
><br>
><br>
> time_t     now = time(0);<br>
>       struct tm  tstruct;<br>
>       char       buf[80];<br>
>       tstruct = *localtime(&now);<br>
>       strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct);<br>
><br>
>      std::ofstream resultfile;<br>
>       char Risultati[] = "D:/Images/MetricResultDeformaion.txt";<br>
><br>
>     resultfile.open(Risultati, std::ios::app);<br>
>     if (resultfile.is_open())<br>
>      {<br>
>         std::cout << "File Open exists\n";<br>
><br>
>      }<br>
><br>
> resultfile<<"Data :"<<buf<<std::endl;<br>
><br>
><br>
><br>
><br>
>   const unsigned int Dimension = 2;<br>
>   typedef unsigned int PixelType;<br>
><br>
>   typedef itk::Image< PixelType, Dimension >  FixedImageType;<br>
>   typedef itk::Image< PixelType, Dimension >  MovingImageType;<br>
><br>
><br>
><br>
><br>
>   typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;<br>
>   typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;<br>
>   typedef itk::GDCMImageIO GDCMType;<br>
>   GDCMType::Pointer gdcm=GDCMType::New();<br>
>   FixedImageReaderType::Pointer fixedImageReader   =<br>
> FixedImageReaderType::New();<br>
>   MovingImageReaderType::Pointer movingImageReader =<br>
> MovingImageReaderType::New();<br>
><br>
>   char* filename1="D:/Images/def00001.dcm";<br>
>   char* filename2="D:/Images/def100001.dcm";<br>
>   fixedImageReader->SetFileName( filename1 );<br>
>   movingImageReader->SetFileName( filename2 );<br>
>   fixedImageReader->SetImageIO(gdcm);<br>
>   movingImageReader->SetImageIO(gdcm);<br>
><br>
>   resultfile<<filename1<<std::endl;<br>
>   resultfile<<filename2<<std::endl;<br>
><br>
>   fixedImageReader->Update();<br>
>   movingImageReader->Update();<br>
><br>
>   typedef itk::ShrinkImageFilter<MovingImageType,MovingImageType><br>
> ShrinkFilterType;<br>
> ShrinkFilterType::Pointer shrinkFilter = ShrinkFilterType::New();<br>
> shrinkFilter->SetShrinkFactors( 2 );<br>
> shrinkFilter->SetInput( fixedImageReader->GetOutput() );<br>
> shrinkFilter->Update();<br>
><br>
>   typedef double                                      InternalPixelType;<br>
>   typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<br>
>   typedef itk::CastImageFilter< FixedImageType, InternalImageType ><br>
> FixedImageCasterType;<br>
>   typedef itk::CastImageFilter< MovingImageType, InternalImageType ><br>
> MovingImageCasterType;<br>
><br>
>   FixedImageCasterType::Pointer fixedImageCaster =<br>
> FixedImageCasterType::New();<br>
>   MovingImageCasterType::Pointer movingImageCaster=<br>
> MovingImageCasterType::New();<br>
><br>
>   fixedImageCaster->SetInput( shrinkFilter->GetOutput() );<br>
>   movingImageCaster->SetInput( fixedImageReader->GetOutput() );<br>
><br>
>   fixedImageCaster->Update();<br>
>   movingImageCaster->Update();<br>
><br>
>   typedef itk::HistogramMatchingImageFilter<<br>
> InternalImageType,InternalImageType >   MatchingFilterType;<br>
>   MatchingFilterType::Pointer matcher = MatchingFilterType::New();<br>
><br>
>   matcher->SetInput( movingImageCaster->GetOutput() );<br>
><br>
>   matcher->SetReferenceImage( fixedImageCaster->GetOutput() );<br>
><br>
><br>
>   matcher->SetNumberOfHistogramLevels(1024);<br>
>   matcher->SetNumberOfMatchPoints(7  );<br>
><br>
><br>
>   matcher->ThresholdAtMeanIntensityOn();<br>
><br>
>   typedef itk::Vector< double, Dimension >           VectorPixelType;<br>
>   typedef itk::Image<  VectorPixelType, Dimension > DisplacementFieldType;<br>
><br>
><br>
><br>
>  typedef<br>
> itk::SymmetricForcesDemonsRegistrationFilter<InternalImageType,InternalImageType,<br>
> DisplacementFieldType> RegistrationFilterType;<br>
>   RegistrationFilterType::Pointer filter = RegistrationFilterType::New();<br>
><br>
><br>
><br>
>   CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<br>
>   filter->AddObserver( itk::IterationEvent(), observer );<br>
><br>
><br>
><br>
>   filter->SetFixedImage( fixedImageCaster->GetOutput() );<br>
>   filter->SetMovingImage( matcher->GetOutput());<br>
>   filter->SetNumberOfIterations( 256 );<br>
>   filter->SetStandardDeviations( 4.0 );<br>
><br>
><br>
><br>
>   try<br>
> {<br>
> filter->Update();<br>
> }<br>
> catch( itk::ExceptionObject & err )<br>
> {<br>
> std::cerr << "ExceptionObject caught !" << std::endl;<br>
> std::cerr << err << std::endl;<br>
> return EXIT_FAILURE;<br>
> }<br>
><br>
><br>
>   typedef itk::WarpImageFilter<  MovingImageType, MovingImageType,<br>
> DisplacementFieldType  >     WarperType;<br>
>   typedef itk::LinearInterpolateImageFunction< MovingImageType,   double ><br>
> InterpolatorType;<br>
>   WarperType::Pointer warper = WarperType::New();<br>
>   InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
>   FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();<br>
><br>
>   warper->SetInput( movingImageReader->GetOutput() );<br>
>   warper->SetInterpolator( interpolator );<br>
>   warper->SetOutputSpacing( fixedImage->GetSpacing() );<br>
>   warper->SetOutputOrigin( fixedImage->GetOrigin() );<br>
>   warper->SetOutputDirection( fixedImage->GetDirection() );<br>
><br>
>   warper->SetDisplacementField( filter->GetOutput() );<br>
><br>
>   warper->Update();<br>
><br>
><br>
><br>
>   typedef  unsigned char                           OutputPixelType;<br>
>   typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br>
>   typedef itk::CastImageFilter<<br>
>                         MovingImageType,<br>
>                         OutputImageType >          CastFilterType;<br>
>   typedef itk::ImageFileWriter< OutputImageType >  WriterType;<br>
><br>
>   WriterType::Pointer      writer =  WriterType::New();<br>
>   CastFilterType::Pointer  caster =  CastFilterType::New();<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
>   std::cout<<"last metric value "<<filter->GetMetric()<<std::endl;<br>
>   resultfile<<"last metric value "<<filter->GetMetric()<<std::endl;<br>
>   writer->SetFileName( "D:/Images/new.dcm" );<br>
><br>
>   caster->SetInput( warper->GetOutput() );<br>
>   caster->Update();<br>
>     writer->SetInput( caster->GetOutput()   );<br>
> writer->SetImageIO(gdcm);<br>
>   writer->Update();<br>
><br>
><br>
>     return EXIT_SUCCESS;<br>
> }<br>
><br>
><br>
><br>
><br>
><br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
><br>
</blockquote></div><br></div>