Skip to content

Commit

Permalink
ENH: Support rigid motion correction as well as affine
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpa committed Nov 17, 2015
1 parent de13a3a commit c47dc40
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions Examples/antsMotionCorrDiffusionDirection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int ants_motion_directions( itk::ants::CommandLineParser *parser )

std::vector<CompositeTransformType::Pointer> CompositeTransformVector;


typedef itk::Euler3DTransform<RealType> RigidTransformType;
typedef itk::AffineTransform<RealType, ImageDimension> AffineTransformType;

typedef itk::ants::CommandLineParser ParserType;
Expand Down Expand Up @@ -249,12 +249,12 @@ int ants_motion_directions( itk::ants::CommandLineParser *parser )

for ( unsigned int i=2; i < schemeMatrix.rows(); i++ )
{
for ( unsigned int j=0; j < 3; j++ )
{
directionArray(i-2,j) = schemeMatrix(i-2,j);
}
for ( unsigned int j=0; j < 3; j++ )
{
directionArray(i-2,j) = schemeMatrix(i-2,j);
}
}

}

bool transposeArray = true;
Expand Down Expand Up @@ -358,13 +358,33 @@ int ants_motion_directions( itk::ants::CommandLineParser *parser )
AffineTransformType::Pointer affineTransform = AffineTransformType::New();
AffineTransformType::Pointer directionTransform = AffineTransformType::New();
AffineTransformType::ParametersType params;
params.SetSize( nTransformParams );
for ( unsigned int t=0; t<nTransformParams; t++ )
{
params[t] = mocoDataArray->GetMatrix()(i,t+2);
}
affineTransform->SetParameters( params );
affineTransform->GetInverse( directionTransform );

if (nTransformParams == 6) {
RigidTransformType::Pointer rigid = RigidTransformType::New();
RigidTransformType::ParametersType rParams;

rParams.SetSize( nTransformParams );
for ( unsigned int t=0; t<nTransformParams; t++ )
{
rParams[t] = mocoDataArray->GetMatrix()(i,t+2);
}
rigid->SetParameters( rParams );
affineTransform->SetMatrix( rigid->GetMatrix() );
affineTransform->SetTranslation( rigid->GetTranslation() );
}
else if (nTransformParams == 12) {
params.SetSize( nTransformParams );
for ( unsigned int t=0; t<nTransformParams; t++ )
{
params[t] = mocoDataArray->GetMatrix()(i,t+2);
}
affineTransform->SetParameters( params );
affineTransform->GetInverse( directionTransform );
}
else {
// Not rigid (6 params) or affine (12), something is wrong
return EXIT_FAILURE;
}

//std::cout << affineTransform->GetTranslation() << std::endl;

Expand Down Expand Up @@ -600,9 +620,8 @@ int antsMotionCorrDiffusionDirection( std::vector<std::string> args, std::ostrea
std::cout << std::endl << "Running " << argv[0] << " for 3-dimensional images." << std::endl
<< std::endl;

ants_motion_directions( parser );
return ants_motion_directions( parser );

return 0;
}

} // namespace ants

0 comments on commit c47dc40

Please sign in to comment.