diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp index 2b5908605e..a5b169a137 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.cpp @@ -1,118 +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)); + ApplyTransformationToImage(m_MovingReference,transf); + m_RegisteredImages.push_back(m_MovingReference); // 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)); + ApplyTransformationToImage(*it,transf); + m_RegisteredImages.push_back(*it); } } return m_RegisteredImages; } -mitk::Image::Pointer mitk::BatchedRegistration::ApplyTransformationToImage(mitk::Image::Pointer &img, const mitk::BatchedRegistration::TransformType &transformation) const +void 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::Image::Pointer mask) { mitk::PyramidImageRegistrationMethod::Pointer registrationMethod = mitk::PyramidImageRegistrationMethod::New(); registrationMethod->SetFixedImage( fixedImage ); if (mask.IsNotNull()) { - registrationMethod->SetFixedImageMask(mask); - registrationMethod->SetUseFixedImageMask(true); + 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 TransformType transformation; mitk::PyramidImageRegistrationMethod::TransformMatrixType rotationMatrix; - rotationMatrix = registrationMethod->GetLastRotationMatrix(); + rotationMatrix = registrationMethod->GetLastRotationMatrix().transpose(); 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); } } - transformation.set(0,3,param[3]); - transformation.set(1,3,param[4]); - transformation.set(2,3,param[5]); + 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; } diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h index d12f582084..8d92ea1d9a 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/Registration/mitkBatchedRegistration.h @@ -1,80 +1,79 @@ #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; + void ApplyTransformationToImage(mitk::Image::Pointer& img, const TransformType& transformation) const; 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