Commit e0cb8f9e authored by Christophe Palmann's avatar Christophe Palmann

ENH : two stopping criteria, subpixel and convergence accuracies

parent 81d5287a
......@@ -199,6 +199,12 @@ private:
SetParameterDescription( "m", "Choose the metric used for block matching. Available metrics are cross-correlation (CC), cross-correlation with subtracted mean (CCSM), mean-square difference (MSD), mean reciprocal square difference (MRSD) and mutual information (MI). Default is cross-correlation" );
MandatoryOff("m");
AddParameter(ParameterType_Float, "spa", "SubPixelAccuracy");
SetParameterDescription( "spa", "Metric extrema location will be refined up to the given accuracy. Default is 0.01" );
SetDefaultParameterFloat("spa", 0.01);
SetMinimumParameterFloatValue("spa", 0.0);
MandatoryOff("spa");
AddParameter(ParameterType_Float, "cva", "ConvergenceAccuracy");
SetParameterDescription( "cva", "Metric extrema will be refined up to the given accuracy. Default is 0.01" );
SetDefaultParameterFloat("cva", 0.01);
......@@ -249,8 +255,6 @@ private:
radius[0] = GetParameterInt("mrx");
radius[1] = GetParameterInt("mry");
double accuracy = static_cast<double>(GetParameterFloat("cva"));
ssrate[0] = GetParameterFloat("ssrx");
ssrate[1] = GetParameterFloat("ssry");
......@@ -265,12 +269,22 @@ private:
otbAppLogINFO("Metric radius : "<<radius<<" (pixels)");
otbAppLogINFO("Sub-sampling rate : "<<ssrate<<" (pixels)");
otbAppLogINFO("Coarse offset : "<<initialOffset<<" (physical unit)");
otbAppLogINFO("Accuracy : "<<accuracy<<" (physical unit)");
m_Registration = RegistrationFilterType::New();
m_Registration->SetRadius(radius);
m_Registration->SetSearchRadius(sradius);
m_Registration->SetConvergenceAccuracy(accuracy);
if (IsParameterEnabled("cva") && HasValue("cva"))
{
double convAccuracy = static_cast<double>(GetParameterFloat("cva"));
m_Registration->SetConvergenceAccuracy(convAccuracy);
otbAppLogINFO("Convergence Accuracy : "<<convAccuracy<<" (physical unit)");
}
if (IsParameterEnabled("spa") && HasValue("spa"))
{
double subPixAccuracy = static_cast<double>(GetParameterFloat("spa"));
m_Registration->SetSubPixelAccuracy(subPixAccuracy);
otbAppLogINFO("SubPixel Accuracy : "<<subPixAccuracy<<" (physical unit)");
}
m_Registration->SetGridStep(ssrate);
m_Registration->SetInitialOffset(initialOffset);
......
......@@ -84,7 +84,8 @@ otb_test_application(NAME apTvDmFineRegistrationTest
-mry 3
-ssrx 8
-ssry 8
-cva 0.1
-spa 0.1
-cva 0.01
-cox -2
-vmlt 0.999
VALID --compare-image ${EPSILON_10}
......
......@@ -136,6 +136,10 @@ public:
itkSetMacro(ConvergenceAccuracy, double);
itkGetMacro(ConvergenceAccuracy, double);
/** Set/Get subpixel accuracy */
itkSetMacro(SubPixelAccuracy, double);
itkGetMacro(SubPixelAccuracy, double);
/** Set/Get max number of iterations */
itkSetMacro(MaxIter, int);
itkGetMacro(MaxIter, int);
......@@ -218,6 +222,7 @@ private:
/** Search step */
double m_ConvergenceAccuracy;
double m_SubPixelAccuracy;
/** Max number of iterations */
int m_MaxIter;
......
......@@ -44,6 +44,7 @@ FineRegistrationImageFilter<TInputImage, T0utputCorrelation, TOutputDisplacement
m_SearchRadius.Fill(4);
// Default sub-pixel precision
m_SubPixelAccuracy = 0.1;
m_ConvergenceAccuracy = 0.01;
// Max number of iterations
......@@ -335,6 +336,7 @@ FineRegistrationImageFilter<TInputImage, TOutputCorrelation, TOutputDisplacement
out2=in3;
out3=in1+gn*(in2-in1);
out4=in2-gn*(in2-in1);
}
......@@ -499,7 +501,10 @@ FineRegistrationImageFilter<TInputImage, TOutputCorrelation, TOutputDisplacement
bool exitWhile=false;
int nbIter=0;
double bestvalold=itk::NumericTraits<double>::max(),bestval=optMetric;
typename TranslationType::ParametersType oldOptParams=optParams;
double diff=itk::NumericTraits<double>::max();
double diffParamx=itk::NumericTraits<double>::max();
double diffParamy=itk::NumericTraits<double>::max();
//init
fc=callMetric(cx,cy,fc,exitWhile);
......@@ -507,7 +512,10 @@ FineRegistrationImageFilter<TInputImage, TOutputCorrelation, TOutputDisplacement
updateMinimize(fc,fd);
//loop
while ((diff>m_ConvergenceAccuracy) && (!exitWhile) && (nbIter<=m_MaxIter))
while ( (diffParamx > m_SubPixelAccuracy || diffParamy > m_SubPixelAccuracy)
&& (diff>m_ConvergenceAccuracy)
&& (!exitWhile)
&& (nbIter<=m_MaxIter))
{
nbIter++;
......@@ -551,8 +559,12 @@ FineRegistrationImageFilter<TInputImage, TOutputCorrelation, TOutputDisplacement
if(!m_Minimize)
bestval=-bestval;
diff= fabs(bestval-bestvalold);
diffParamx=fabs(optParams[0]-oldOptParams[0]);
diffParamy=fabs(optParams[1]-oldOptParams[1]);
bestvalold=bestval;
oldOptParams=optParams;
}
......
......@@ -168,7 +168,7 @@ otb_add_test(NAME dmTvFineRegistrationImageFilterTestWithMeanSquare COMMAND otbD
${TEMP}/feTvFineRegistrationImageFilterTestWithMeanSquareField.tif # output fieldFileName
3 # radius
2 # sradius
0.1 # precision
0.01 # precision
2 # Mean square
1 # Grid step
0 # Initial offset x
......@@ -188,7 +188,7 @@ otb_add_test(NAME dmTvFineRegistrationImageFilterTestWithMeanReciprocalDifferenc
${TEMP}/feTvFineRegistrationImageFilterTestWithMeanReciprocalDifferenceField.tif # output fieldFileName
3 # radius
2 # sradius
0.1 # precision
0.01 # precision
3 # Mean reciprocal difference
1 # Grid step
0 # Initial offset x
......@@ -208,7 +208,7 @@ otb_add_test(NAME dmTvFineRegistrationImageFilterTestWithNormalizedCorrelation C
${TEMP}/feTvFineRegistrationImageFilterTestWithNormalizedCorrelationField.tif # output fieldFileName
3 # radius
2 # sradius
0.1 # precision
0.01 # precision
1 # Normalized Correlation
1 # Grid step
0 # Initial offset x
......@@ -228,7 +228,7 @@ otb_add_test(NAME dmTvFineRegistrationImageFilterTestWithCorrelation COMMAND otb
${TEMP}/feTvFineRegistrationImageFilterTestWithCorrelationField.tif # output fieldFileName
3 # radius
2 # sradius
0.1 # precision
0.01 # precision
0 # Correlation
1 # Grid step
0 # Initial offset x
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment