Skip to content

Commit e9c4cc0

Browse files
authored
Merge pull request #1350 from ANTsX/antsMotionCorrSmooth
ENH: Allow smoothing to be specified in mm or vox
2 parents ac22e7a + d89cb25 commit e9c4cc0

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

Examples/antsMotionCorr.cxx

+32-5
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,30 @@ ants_motion(itk::ants::CommandLineParser * parser)
872872

873873
// Get smoothing sigmas
874874

875-
std::vector<float> sigmas =
876-
parser->ConvertVector<float>(smoothingSigmasOption->GetFunction(currentStage)->GetName());
875+
std::string smoothingSigmasString = smoothingSigmasOption->GetFunction(currentStage)->GetName();
876+
877+
bool smoothingSigmasAreInPhysicalUnits = false;
878+
879+
const size_t mmPosition = smoothingSigmasString.find("mm");
880+
const size_t voxPosition = smoothingSigmasString.find("vox");
881+
882+
if (mmPosition != std::string::npos)
883+
{
884+
smoothingSigmasString.replace(mmPosition, 2, "");
885+
smoothingSigmasAreInPhysicalUnits = true;
886+
}
887+
else if (voxPosition != std::string::npos)
888+
{
889+
smoothingSigmasString.replace(voxPosition, 3, "");
890+
smoothingSigmasAreInPhysicalUnits = false;
891+
}
892+
else
893+
{
894+
smoothingSigmasAreInPhysicalUnits = false;
895+
}
896+
897+
std::vector<float> sigmas = parser->ConvertVector<float>(smoothingSigmasString);
898+
877899
typename AffineRegistrationType::SmoothingSigmasArrayType smoothingSigmasPerLevel;
878900
smoothingSigmasPerLevel.SetSize(sigmas.size());
879901

@@ -890,6 +912,7 @@ ants_motion(itk::ants::CommandLineParser * parser)
890912
}
891913
if (verbose)
892914
std::cout << " smoothing sigmas per level: " << smoothingSigmasPerLevel << std::endl;
915+
std::cout << " smoothing sigmas in physical space units: " << smoothingSigmasAreInPhysicalUnits << std::endl;
893916
}
894917

895918
// the fixed image is a reference image in 3D while the moving is a 4D image
@@ -1218,6 +1241,7 @@ ants_motion(itk::ants::CommandLineParser * parser)
12181241
affineRegistration->SetNumberOfLevels(numberOfLevels);
12191242
affineRegistration->SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
12201243
affineRegistration->SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);
1244+
affineRegistration->SetSmoothingSigmasAreSpecifiedInPhysicalUnits(smoothingSigmasAreInPhysicalUnits);
12211245
affineRegistration->SetMetricSamplingStrategy(metricSamplingStrategy);
12221246
affineRegistration->SetMetricSamplingPercentage(samplingPercentage);
12231247
affineRegistration->SetMetric(metric);
@@ -1292,6 +1316,7 @@ ants_motion(itk::ants::CommandLineParser * parser)
12921316
rigidRegistration->SetNumberOfLevels(numberOfLevels);
12931317
rigidRegistration->SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
12941318
rigidRegistration->SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);
1319+
rigidRegistration->SetSmoothingSigmasAreSpecifiedInPhysicalUnits(smoothingSigmasAreInPhysicalUnits);
12951320
rigidRegistration->SetMetric(metric);
12961321
rigidRegistration->SetMetricSamplingStrategy(
12971322
static_cast<typename RigidRegistrationType::MetricSamplingStrategyEnum>(metricSamplingStrategy));
@@ -1397,7 +1422,7 @@ ants_motion(itk::ants::CommandLineParser * parser)
13971422
displacementFieldRegistration->SetNumberOfLevels(numberOfLevels);
13981423
displacementFieldRegistration->SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
13991424
displacementFieldRegistration->SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);
1400-
displacementFieldRegistration->SetSmoothingSigmasAreSpecifiedInPhysicalUnits(false);
1425+
displacementFieldRegistration->SetSmoothingSigmasAreSpecifiedInPhysicalUnits(smoothingSigmasAreInPhysicalUnits);
14011426
displacementFieldRegistration->SetMetricSamplingStrategy(
14021427
static_cast<typename DisplacementFieldRegistrationType::MetricSamplingStrategyEnum>(metricSamplingStrategy));
14031428
displacementFieldRegistration->SetMetricSamplingPercentage(samplingPercentage);
@@ -1518,7 +1543,7 @@ ants_motion(itk::ants::CommandLineParser * parser)
15181543
displacementFieldRegistration->SetNumberOfLevels(numberOfLevels);
15191544
displacementFieldRegistration->SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
15201545
displacementFieldRegistration->SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);
1521-
displacementFieldRegistration->SetSmoothingSigmasAreSpecifiedInPhysicalUnits(false);
1546+
displacementFieldRegistration->SetSmoothingSigmasAreSpecifiedInPhysicalUnits(smoothingSigmasAreInPhysicalUnits);
15221547
displacementFieldRegistration->SetLearningRate(learningRate);
15231548
displacementFieldRegistration->SetConvergenceThreshold(1.e-8);
15241549
displacementFieldRegistration->SetConvergenceWindowSize(10);
@@ -1884,7 +1909,9 @@ antsMotionCorrInitializeCommandLineOptions(itk::ants::CommandLineParser * parser
18841909
}
18851910

18861911
{
1887-
std::string description = std::string("Specify the amount of smoothing at each level.");
1912+
std::string description =
1913+
std::string("Specify the sigma for smoothing at each level. Smoothing may be specified ") +
1914+
std::string("in mm units or voxels with \"AxBxCmm\" or \"AxBxCvox\". No units implies voxels.");
18881915

18891916
OptionType::Pointer option = OptionType::New();
18901917
option->SetLongName("smoothingSigmas");

0 commit comments

Comments
 (0)