Exemplo n.º 1
0
void QmitkTrackingWorker::run()
{
  m_View->m_GlobalTracker = QmitkGibbsTrackingView::GibbsTrackingFilterType::New();

  MITK_INFO << "Resampling mask images";
  // setup resampler
  typedef itk::ResampleImageFilter<QmitkGibbsTrackingView::MaskImgType, QmitkGibbsTrackingView::MaskImgType, float> ResamplerType;
  ResamplerType::Pointer resampler = ResamplerType::New();
  resampler->SetOutputSpacing( m_View->m_ItkQBallImage->GetSpacing() );
  resampler->SetOutputOrigin( m_View->m_ItkQBallImage->GetOrigin() );
  resampler->SetOutputDirection( m_View->m_ItkQBallImage->GetDirection() );
  resampler->SetSize( m_View->m_ItkQBallImage->GetLargestPossibleRegion().GetSize() );

  // resample mask image
  resampler->SetInput( m_View->m_MaskImage );
  resampler->SetDefaultPixelValue(0);
  resampler->Update();
  m_View->m_MaskImage = resampler->GetOutput();

  if (m_View->m_GfaImage.IsNotNull())
  {
    ResamplerType::Pointer resampler = ResamplerType::New();
    resampler->SetOutputSpacing( m_View->m_ItkQBallImage->GetSpacing() );
    resampler->SetOutputOrigin( m_View->m_ItkQBallImage->GetOrigin() );
    resampler->SetOutputDirection( m_View->m_ItkQBallImage->GetDirection() );
    resampler->SetSize( m_View->m_ItkQBallImage->GetLargestPossibleRegion().GetSize() );
    resampler->SetInput( m_View->m_GfaImage );
    resampler->SetDefaultPixelValue(0);
    resampler->Update();
    m_View->m_GfaImage = resampler->GetOutput();
  }

  m_View->m_GlobalTracker->SetInput0(m_View->m_ItkQBallImage.GetPointer());
  m_View->m_GlobalTracker->SetMaskImage(m_View->m_MaskImage);
  m_View->m_GlobalTracker->SetGfaImage(m_View->m_GfaImage);
  m_View->m_GlobalTracker->SetTempStart((float)m_View->m_Controls->m_StartTempSlider->value()/100);
  m_View->m_GlobalTracker->SetTempEnd((float)m_View->m_Controls->m_EndTempSlider->value()/10000);
  m_View->m_GlobalTracker->SetNumIt(m_View->m_Iterations);
  m_View->m_GlobalTracker->SetParticleWeight((float)m_View->m_Controls->m_ParticleWeightSlider->value()/10000);
  m_View->m_GlobalTracker->SetSubtractMean(m_View->m_Controls->m_MeanSubtractionCheckbox->isChecked());
  m_View->m_GlobalTracker->SetParticleWidth((float)(m_View->m_Controls->m_ParticleWidthSlider->value())/10);
  m_View->m_GlobalTracker->SetParticleLength((float)(m_View->m_Controls->m_ParticleLengthSlider->value())/10);
  m_View->m_GlobalTracker->SetInexBalance((float)m_View->m_Controls->m_InExBalanceSlider->value()/10);
  m_View->m_GlobalTracker->SetFiberLength(m_View->m_Controls->m_FiberLengthSlider->value());

  m_View->m_GlobalTracker->Update();
  m_View->m_TrackingThread.quit();
}
Exemplo n.º 2
0
void GibbsTrackingFilter< ItkQBallImageType >::PrepareMaskImage()
{
    if(m_MaskImage.IsNull())
    {
        MITK_INFO << "GibbsTrackingFilter: generating default mask image";
        m_MaskImage = ItkFloatImageType::New();
        m_MaskImage->SetSpacing( m_QBallImage->GetSpacing() );
        m_MaskImage->SetOrigin( m_QBallImage->GetOrigin() );
        m_MaskImage->SetDirection( m_QBallImage->GetDirection() );
        m_MaskImage->SetRegions( m_QBallImage->GetLargestPossibleRegion() );
        m_MaskImage->Allocate();
        m_MaskImage->FillBuffer(1.0);
    }
    else if ( m_MaskImage->GetLargestPossibleRegion().GetSize()[0]!=m_QBallImage->GetLargestPossibleRegion().GetSize()[0] ||
         m_MaskImage->GetLargestPossibleRegion().GetSize()[1]!=m_QBallImage->GetLargestPossibleRegion().GetSize()[1] ||
         m_MaskImage->GetLargestPossibleRegion().GetSize()[2]!=m_QBallImage->GetLargestPossibleRegion().GetSize()[2] ||
         m_MaskImage->GetSpacing()[0]!=m_QBallImage->GetSpacing()[0] ||
         m_MaskImage->GetSpacing()[1]!=m_QBallImage->GetSpacing()[1] ||
         m_MaskImage->GetSpacing()[2]!=m_QBallImage->GetSpacing()[2] )
    {
        MITK_INFO << "GibbsTrackingFilter: resampling mask image";
        typedef itk::ResampleImageFilter< ItkFloatImageType, ItkFloatImageType, float > ResamplerType;
        ResamplerType::Pointer resampler = ResamplerType::New();
        resampler->SetOutputSpacing( m_QBallImage->GetSpacing() );
        resampler->SetOutputOrigin( m_QBallImage->GetOrigin() );
        resampler->SetOutputDirection( m_QBallImage->GetDirection() );
        resampler->SetSize( m_QBallImage->GetLargestPossibleRegion().GetSize() );

        resampler->SetInput( m_MaskImage );
        resampler->SetDefaultPixelValue(0.0);
        resampler->Update();
        m_MaskImage = resampler->GetOutput();
        MITK_INFO << "GibbsTrackingFilter: resampling finished";
    }
}
Exemplo n.º 3
0
	void initialiseFilters() {
		// resamplers
		transform = TransformType::New();
	  transform->SetIdentity();
    volumeInterpolator = VolumeInterpolatorType::New();
		maskVolumeInterpolator = MaskVolumeInterpolatorType::New();
		resampler = ResamplerType::New();
    resampler->SetInput( originalImage );
		resampler->SetInterpolator( volumeInterpolator );
		resampler->SetOutputSpacing( resamplerSpacing );
		resampler->SetSize( resamplerSize );
		resampler->SetTransform( transform );
		resampler->SetDefaultPixelValue( 127 );
		maskResampler = MaskResamplerType::New();
		maskResampler->SetInput( originalMask );
		maskResampler->SetInterpolator( maskVolumeInterpolator );
		maskResampler->SetOutputSpacing( resamplerSpacing );
		maskResampler->SetSize( resamplerSize );
		maskResampler->SetTransform( transform );
		
		// extract image filters
    sliceExtractor = SliceExtractorType::New();
    sliceExtractor->SetInput( resampler->GetOutput() );
		maskSliceExtractor = MaskSliceExtractorType::New();
    maskSliceExtractor->SetInput( maskResampler->GetOutput() );
    
    // masks
    for(unsigned int i=0; i<resamplerSize[2]; i++) {
  		masks2D.push_back( MaskType2D::New() );
    }		
	}
Exemplo n.º 4
0
 void ResampleResult(const char* name) {
     InterpolatorNN::Pointer resampleInterpolator = InterpolatorNN::New();
     ResamplerType::Pointer resample = ResamplerType::New();
     resample->SetTransform(_finalTransform);
     resample->SetInput(_src);
     resample->UseReferenceImageOn();
     resample->SetReferenceImage(_dst);
     resample->SetInterpolator(resampleInterpolator);
     resample->Update();
     ImageType::Pointer resampledImage = resample->GetOutput();
     itkcmds::itkImageIO<ImageType> io;
     io.WriteImageT(name, resampledImage);
 }
Exemplo n.º 5
0
// ------------------------------------------------------------------------
void ValveNormaliser::AlignValve(const ValveType::Pointer &input, ValveType::Pointer &output)
{
	if(!output) output = ValveType::New();

	ImageType::Pointer image = input->GetImage();
	PointType p1 = input->GetP1();
	PointType p2 = input->GetP2();


	// tranlsation to the origin
	m_Transform = TransformType::New();
	m_Transform->SetCenter(p1);

	TransformType::OutputVectorType axis;
	for(unsigned int i = 0; i < 3; i++)
	{
		axis[i] = -image->GetDirection()(i,2);
	}

	itk::Vector<double, 3> vec1, vec2;
	for(unsigned int i = 0; i < 3; i++)
	{
		vec1[i] = p2[i]-p1[i];
		vec2[i] = image->GetDirection()(i,0);
	}

	vec1.Normalize();
	vec2.Normalize();

	double angle = acos(vec2*vec1);
	itk::Vector<double,3> axis2 = itk::CrossProduct(vec1,vec2);
	axis2.Normalize();

	m_Transform->Rotate3D(axis, angle);

	typedef itk::ResampleImageFilter<ImageType, ImageType> ResamplerType;
	ResamplerType::Pointer resampler = ResamplerType::New();
	resampler->SetInput(image);
	resampler->SetTransform(m_Transform);
	resampler->SetOutputParametersFromImage(image);
	resampler->Update();


	// create the output 
	if(!output) output = ValveLine<3>::New();
	output->SetImage(resampler->GetOutput());
	output->SetP1(m_Transform->TransformPoint(input->GetP1()));
	output->SetP2(m_Transform->GetInverseTransform()->TransformPoint(input->GetP2()));
	output->UpdateIndexs();
}
Exemplo n.º 6
0
// ------------------------------------------------------------------------
void ValveNormaliser::UnNormalise()
{
	ImageType::Pointer image = m_Valve->GetImage();

	typedef itk::ResampleImageFilter<ImageType, ImageType> ResamplerType;
	ResamplerType::Pointer resampler = ResamplerType::New();
	resampler->SetInput(image);
	resampler->SetTransform(m_Transform->GetInverseTransform());
	resampler->SetOutputParametersFromImage(image);
	resampler->Update();

	m_Output = ValveType::New();
	m_Output->SetImage(resampler->GetOutput());
	m_Output->SetP1(m_Transform->TransformPoint(m_Valve->GetP1()));
	m_Output->SetP2(m_Transform->TransformPoint(m_Valve->GetP2()));
	m_Output->UpdateIndexs();

	if(m_FlipPoints)
		FlipPoints(m_Output, m_Output);

	if(m_Flip)
		FlipValve(m_Output, m_Output);

}
int main(int argc, char** argv )
{
/**
 *   /home/morgan/invaginatingleg/invagination/invagination_T0.ome.tif
 *   /home/morgan/invaginatingleg/invagination/invagination_T1.ome.tif
 *   /home/morgan/invaginatingleg/invagination/invagination_T2.ome.tif
 *   /home/morgan/invaginatingleg/invagination/invagination_T3.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T4.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T5.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T6.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T7.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T8.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T9.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T10.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T11.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T12.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T13.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T14.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T15.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T16.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T17.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T18.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T19.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T20.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T21.ome.tif
 *   /home/morgan/invaginationmasked/invaginated_T22.ome.tif
 *   output
 */
	std::vector<std::string> inputFiles;
    typedef float PixelType;
    // Fixed Image Type
    typedef itk::Image<PixelType,3>               FixedImageType;

    // Moving Image Type
    typedef itk::Image<PixelType,3>               MovingImageType;

    typedef FixedImageType::SpacingType SpacingType;

    SpacingType spacing;
    //spacing[0]=0.3107403;
    //spacing[1]=0.3107403;
    //spacing[2]=0.739833;


    spacing[0]=0.1569476;
    spacing[1]=0.1569476;
    spacing[2]=0.6209697;
    // Transform Type
    typedef itk::VersorRigid3DTransform< double > TransformType;
#if 0


	inputFiles.push_back("/home/morgan/invaginatingleg/invagination/invagination_T0.ome.tif");
    inputFiles.push_back("/home/morgan/invaginatingleg/invagination/invagination_T1.ome.tif");



    typedef   float          VectorComponentType;

    typedef   itk::Vector< VectorComponentType, 3 >    VectorType;
    typedef   itk::Image< VectorType,  3 >   DeformationFieldType;







    typedef itk::ImageFileReader<FixedImageType> FixedImageReaderType;
    typedef itk::ImageFileReader<MovingImageType> MovingImageReaderType;

    FixedImageReaderType::Pointer fixedImageReader=FixedImageReaderType::New();
    MovingImageReaderType::Pointer movingImageReader=MovingImageReaderType::New();

    fixedImageReader->SetFileName(inputFiles[0]);
    movingImageReader->SetFileName(inputFiles[1]);
    fixedImageReader->Update();
    movingImageReader->Update();
    FixedImageType::Pointer     fixedImage    = fixedImageReader->GetOutput();
    MovingImageType::Pointer    movingImage   = movingImageReader->GetOutput();

    fixedImage->SetSpacing(spacing);
    movingImage->SetSpacing(spacing);

    typedef itk::VersorRigid3DTransform< double > Rigid3DTransformType;

    typedef itk::LandmarkBasedTransformInitializer< Rigid3DTransformType, FixedImageType, MovingImageType >
        LandmarkBasedTransformInitializerType;

    LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer =
      LandmarkBasedTransformInitializerType::New();
    //  Create source and target landmarks.
    typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer     LandmarkContainerType;
    typedef LandmarkBasedTransformInitializerType::LandmarkPointType          LandmarkPointType;

    LandmarkContainerType fixedLandmarks;
    LandmarkContainerType movingLandmarks;

    LandmarkPointType fixedPoint;
    LandmarkPointType movingPoint;






    fixedPoint[0] = 37.510;
    fixedPoint[1] = 34.685;
    fixedPoint[2] = 52*spacing[2];

    movingPoint[0] = 31.468;
    movingPoint[1] = 27.593;
    movingPoint[2] = 50*spacing[2];

    fixedLandmarks.push_back( fixedPoint );
    movingLandmarks.push_back( movingPoint );



    fixedPoint[0] = 32.645;
    fixedPoint[1] = 33.901;
    fixedPoint[2] = 52*spacing[2];

    movingPoint[0] = 25.888;
    movingPoint[1] = 26.353;
    movingPoint[2] = 50*spacing[2];

    fixedLandmarks.push_back( fixedPoint );
    movingLandmarks.push_back( movingPoint );


    fixedPoint[0] = 35.784;
    fixedPoint[1] = 37.354;
    fixedPoint[2] = 52*spacing[2];

    movingPoint[0] = 29.918;
    movingPoint[1] = 29.918;
    movingPoint[2] = 50*spacing[2];

    fixedLandmarks.push_back( fixedPoint );
    movingLandmarks.push_back( movingPoint );




    fixedPoint[0] = 33.116;
    fixedPoint[1] = 37.040;
    fixedPoint[2] = 52*spacing[2];

    movingPoint[0] = 26.818;
    movingPoint[1] = 29.608;
    movingPoint[2] = 50*spacing[2];

    fixedLandmarks.push_back( fixedPoint );
    movingLandmarks.push_back( movingPoint );

    landmarkBasedTransformInitializer->SetFixedLandmarks( fixedLandmarks );
    landmarkBasedTransformInitializer->SetMovingLandmarks( movingLandmarks );

    Rigid3DTransformType::Pointer transform = Rigid3DTransformType::New();

    transform->SetIdentity();

    landmarkBasedTransformInitializer->SetTransform(transform);
    landmarkBasedTransformInitializer->InitializeTransform();

    typedef itk::ResampleImageFilter<FixedImageType, MovingImageType, double >    ResampleFilterType;
    ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New();
    resampleFilter->SetInput( movingImage );
    resampleFilter->SetTransform( transform );
    resampleFilter->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
    resampleFilter->SetOutputOrigin(  fixedImage->GetOrigin() );
    resampleFilter->SetOutputSpacing( fixedImage->GetSpacing() );
    resampleFilter->SetOutputDirection( fixedImage->GetDirection() );
    resampleFilter->SetDefaultPixelValue(0);
    resampleFilter->GetOutput();

    // Write the output
    typedef itk::ImageFileWriter<  MovingImageType  > WriterType;
    WriterType::Pointer writer = WriterType::New();
    writer->SetInput (  resampleFilter->GetOutput() );
    writer->SetFileName( "output.ome.tif" );
    writer->Update();

#endif




	for(int i=1;i<argc-1;i++){
		inputFiles.push_back(argv[i]);
	}


	std::string outputPrefix=argv[argc-1];

  int nImages = inputFiles.size();

  std::vector<TransformType::Pointer >transforms(nImages);
  for(int i=0;i<nImages;i++){
	  transforms[i]=TransformType::New();
  }
  transforms[0]->SetIdentity();

  for(int i=1;i<nImages;i++){
	  /*
	   * Read files
	   */
	  std::cout << "Registering " << inputFiles[i] <<" to " <<inputFiles[i-1] << std::endl;
	  typedef itk::ImageFileReader<FixedImageType> FixedImageReaderType;
	  typedef itk::ImageFileReader<MovingImageType> MovingImageReaderType;

	  FixedImageReaderType::Pointer fixedImageReader=FixedImageReaderType::New();
	  MovingImageReaderType::Pointer movingImageReader=MovingImageReaderType::New();

	  fixedImageReader->SetFileName(inputFiles[i-1]);
	  movingImageReader->SetFileName(inputFiles[i]);


	  fixedImageReader->Update();
	  movingImageReader->Update();
	  FixedImageType::Pointer     fixedImage    = fixedImageReader->GetOutput();
	  MovingImageType::Pointer    movingImage   = movingImageReader->GetOutput();

	  fixedImage->SetSpacing(spacing);
	  movingImage->SetSpacing(spacing);
	  FixedImageType::SizeType size= fixedImage->GetLargestPossibleRegion().GetSize();
	  FixedImageType::PointType origin;

	  origin[0]=size[0]*spacing[0]/2;
	  origin[1]=size[1]*spacing[1]/2;
	  origin[2]=size[2]*spacing[2]/2;

	  fixedImage->SetOrigin(origin);
	  movingImage->SetOrigin(origin);

	  RegisterPair<FixedImageType,MovingImageType,TransformType>(fixedImage,movingImage,transforms[i]);
  }

  typedef itk::ResampleImageFilter<MovingImageType,MovingImageType> ResamplerType;
  ResamplerType::Pointer resampler = ResamplerType::New();
  //transform->SetIdentity();
#if 0
  TransformType::ParametersType initialParameters( transform->GetNumberOfParameters() );
  initialParameters.Fill( 0 );
  initialParameters[3] = 1.0;
  initialParameters[4]=10;
  initialParameters[5]=10;
  initialParameters[6]=0;
  transform->SetParameters(initialParameters);
#endif
  for(int i=0;i<nImages;i++){




	  typedef itk::ImageFileReader<MovingImageType> MovingImageReaderType;
	  MovingImageReaderType::Pointer movingImageReader=MovingImageReaderType::New();
	  movingImageReader->SetFileName(inputFiles[i]);
	  movingImageReader->Update();
	  MovingImageType::Pointer    movingImage   = movingImageReader->GetOutput();
	  movingImage->SetSpacing(spacing);


	  MovingImageType::SizeType size = movingImage->GetLargestPossibleRegion().GetSize();



	  MovingImageType::SizeType resampledSize;
	  resampledSize[0]=1280;
	  resampledSize[1]=1280;
	  resampledSize[2]=150;
	  resampler->SetSize(resampledSize );

	  typedef itk::TranslationTransform<double,3> TranslationTransformType;
	  TranslationTransformType::Pointer translationTransform =
	    TranslationTransformType::New();
	  TranslationTransformType::OutputVectorType translation;
	  translation[0] = -20;//-(resampledSize[0]-size[0])/2*spacing[0];
	  translation[1] = -20;// -(resampledSize[1]-size[1])/2*spacing[1];
	  translation[2] = -20; //-(resampledSize[2]-size[2])/2*spacing[2];
	  translationTransform->Translate(translation);

	  typedef itk::CompositeTransform<double,3> CompositeType;
	  CompositeType::Pointer composite = CompositeType::New();


	  composite->AddTransform(translationTransform);

	  for(int k=1;k<=i;k++){
		  composite->AddTransform(transforms[k]);
	  }



	  std::cout << "Origin: " << movingImage->GetOrigin() << std::endl;
	  resampler->SetInput(movingImage);
	  resampler->SetTransform(composite);
	  resampler->SetOutputOrigin(movingImage->GetOrigin());
	  resampler->SetOutputSpacing( movingImage->GetSpacing() );
	  resampler->SetOutputDirection( movingImage->GetDirection() );
	  resampler->SetDefaultPixelValue( 0 );

	  resampler->Update();



	  std::stringstream ss;

	  ss << outputPrefix << "-T" << i << ".ome.tif";
	    std::string filename;
	    ss >> filename;


	  typedef itk::ImageFileWriter<MovingImageType>  MovingImageWriterType;
	  MovingImageWriterType::Pointer movingImageWriter=MovingImageWriterType::New();
	  movingImageWriter->SetFileName(filename);
	  movingImageWriter->SetInput(resampler->GetOutput());
	  movingImageWriter->Update();
	  std::cout << transforms[i] << std::endl;
  }

}