diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp index c902c57a76..2b5908605e 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp @@ -1,114 +1,118 @@ #include "mitkBatchedRegistration.h" #include "mitkPyramidImageRegistrationMethod.h" #include "mitkDiffusionImage.h" #include #include mitk::BatchedRegistration::BatchedRegistration() : m_RegisteredImagesValid(false) { } void mitk::BatchedRegistration::SetFixedImage(mitk::Image::Pointer& fixedImage) { m_FixedImage = fixedImage; } void mitk::BatchedRegistration::SetMovingReferenceImage(Image::Pointer &movingImage) { m_MovingReference = movingImage; m_RegisteredImagesValid = false; } void mitk::BatchedRegistration::SetBatch(std::vector imageBatch) { m_ImageBatch.clear(); m_ImageBatch = imageBatch; } std::vector mitk::BatchedRegistration::GetRegisteredImages() { if (!m_RegisteredImagesValid) { m_RegisteredImages.clear(); // First transform moving reference image TransformType transf = GetTransformation(m_FixedImage, m_MovingReference); // store it as first element in vector m_RegisteredImages.push_back(ApplyTransformationToImage(m_MovingReference,transf)); // apply transformation to whole batch std::vector::const_iterator itEnd = m_ImageBatch.end(); for (std::vector::iterator it = m_ImageBatch.begin(); it != itEnd; ++it) { m_RegisteredImages.push_back(ApplyTransformationToImage(*it,transf)); } } return m_RegisteredImages; } mitk::Image::Pointer mitk::BatchedRegistration::ApplyTransformationToImage(mitk::Image::Pointer &img, const mitk::BatchedRegistration::TransformType &transformation) const { // TODO: perform some magic! mitk::Vector3D translateVector; translateVector[0] = transformation.get(0,3); translateVector[1] = transformation.get(1,3); translateVector[2] = transformation.get(2,3); img->GetGeometry()->Translate(translateVector); itk::ScalableAffineTransform::Pointer rotationTransform; itk::Matrix rotationMatrix; for (int i = 0; i < 3;++i) for (int j = 0; j < 3;++j) rotationMatrix[i][j] = transformation.get(i,j); rotationTransform = itk::ScalableAffineTransform::New(); rotationTransform->SetMatrix(rotationMatrix); itk::ScalableAffineTransform::Pointer geometryTransform = img->GetGeometry()->GetIndexToWorldTransform(); geometryTransform->Compose(rotationTransform); img->GetGeometry()->SetIndexToWorldTransform(geometryTransform); if (dynamic_cast*> (img.GetPointer()) != NULL) { // apply transformation to image geometry as well as to all gradients !? } else { // do regular stuff } return NULL; } -mitk::BatchedRegistration::TransformType mitk::BatchedRegistration::GetTransformation(mitk::Image::Pointer fixedImage, mitk::Image::Pointer movingImage) +mitk::BatchedRegistration::TransformType mitk::BatchedRegistration::GetTransformation(mitk::Image::Pointer fixedImage, mitk::Image::Pointer movingImage, mitk::Image::Pointer mask) { - mitk::Point3D startingOrigin = movingImage->GetGeometry()->GetOrigin(); mitk::PyramidImageRegistrationMethod::Pointer registrationMethod = mitk::PyramidImageRegistrationMethod::New(); registrationMethod->SetFixedImage( fixedImage ); + + if (mask.IsNotNull()) + { + registrationMethod->SetFixedImageMask(mask); + registrationMethod->SetUseFixedImageMask(true); + } registrationMethod->SetTransformToRigid(); registrationMethod->SetCrossModalityOn(); registrationMethod->SetMovingImage(movingImage); registrationMethod->Update(); - // TODO fancy shit, where you query and create a transformation type object thingy - mitk::Point3D endingOrigin = registrationMethod->GetResampledMovingImage()->GetGeometry()->GetOrigin(); + // TODO fancy shit, where you query and create a transformation type object thingy TransformType transformation; mitk::PyramidImageRegistrationMethod::TransformMatrixType rotationMatrix; rotationMatrix = registrationMethod->GetLastRotationMatrix(); + double param[6]; + registrationMethod->GetParameters(param); // first three: euler angles, last three translation for (unsigned int i = 0; i < 3; i++) { for (unsigned int j = 0; j < 3; ++j) { double value = rotationMatrix.get(i,j); transformation.set(i,j, value); } } - double value; - value = endingOrigin[0] - startingOrigin[0]; - transformation.set(0,3,value); - transformation.set(1,3,endingOrigin[1] - startingOrigin[1]); - transformation.set(2,3,endingOrigin[2] - startingOrigin[2]); + transformation.set(0,3,param[3]); + transformation.set(1,3,param[4]); + transformation.set(2,3,param[5]); transformation.set(3,3,1); return transformation; -} \ No newline at end of file +} diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h index 48504b75ff..d12f582084 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h @@ -1,78 +1,80 @@ #ifndef MITKBATCHEDREGISTRATION_H #define MITKBATCHEDREGISTRATION_H // ITK #include // MITK #include #include "mitkCommon.h" #include "mitkImage.h" namespace mitk { /** * @brief The BatchedRegistration class Wrapper to calculate and apply a reference transformation to several images. * * Use if several pictures with the same world geometry are to be registered * to one reference image, the registration is only computed once (for the moving image) and the geometry transformed for the complete * image batch accordingly. Can handle image types that are usually not supported by registrations filters, e.g. fiber bundles and segmentations: * these can be registered if a "registerable" image such as B0/T2 from which they are derived is supplied, since the transformation can be calculated * on those and applied to the derived objects. */ class DiffusionCore_EXPORT BatchedRegistration : public itk::LightObject { public: typedef vnl_matrix_fixed TransformType; mitkClassMacro(BatchedRegistration, itk::LightObject) itkNewMacro(Self) void SetFixedImage(Image::Pointer &fixedImage); + void SetFixedImageMask(Image::Pointer fixedImageMask); + void SetMovingReferenceImage(mitk::Image::Pointer& movingImage); void SetBatch(std::vector imageBatch); /** * @brief GetRegisteredImages returns registered images , * * at position 0 the registered moving reference image is supplied followed all registered images from the batch. */ std::vector GetRegisteredImages(); mitk::Image::Pointer ApplyTransformationToImage(mitk::Image::Pointer& img, const TransformType& transformation) const; - TransformType GetTransformation(mitk::Image::Pointer fixedImage, mitk::Image::Pointer movingImage); + TransformType GetTransformation(mitk::Image::Pointer fixedImage, mitk::Image::Pointer movingImage, mitk::Image::Pointer mask = NULL); protected: BatchedRegistration(); ~BatchedRegistration(){}; private: BatchedRegistration(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented bool m_RegisteredImagesValid; mitk::Image::Pointer m_FixedImage; mitk::Image::Pointer m_MovingReference; /** * @brief m_ImageBatch List of images on which that the reference transformation is applied * */ std::vector m_ImageBatch; /** * @brief m_RegisteredImages List of references to registered images. * */ std::vector m_RegisteredImages; }; } #endif // MITKBATCHEDREGISTRATION_H