diff --git a/Code/BasicFilters/otbMeanShiftImageFilter2.txx b/Code/BasicFilters/otbMeanShiftImageFilter2.txx
index 6ccb5405bc3abb7591c17ff50ea8c9a870927a3c..6c9a333a0b49e1626c5f531fcc872186a403f417 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter2.txx
+++ b/Code/BasicFilters/otbMeanShiftImageFilter2.txx
@@ -681,6 +681,7 @@ MeanShiftImageFilter2<TInputImage,TOutputMetricImage, TOutputImage, TKernel>
     // TODO change the maximum value;
 
     bool hasConverged = false;
+
     while ((iteration < m_MaxIterationNumber) && (!hasConverged))
       {
 
@@ -720,7 +721,7 @@ MeanShiftImageFilter2<TInputImage,TOutputMetricImage, TOutputImage, TKernel>
         rangePixel[comp] += meanShiftVector[spatialNumberOfComponents + comp];
         metricPixel[spatialNumberOfComponents + comp] = meanShiftVector[spatialNumberOfComponents + comp]
             * meanShiftVector[spatialNumberOfComponents + comp];
-        sum += metricPixel[comp];
+        sum += metricPixel[spatialNumberOfComponents+comp];
         }
 
       //TODO replace SSD Test with templated metric