diff --git a/Code/BasicFilters/otbMeanShiftImageFilter2.h b/Code/BasicFilters/otbMeanShiftImageFilter2.h
index 658c1d9d39065e30cbae89497a18d555d72c346e..055291b0a1e6104c800082a2d342105980e0d2bf 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter2.h
+++ b/Code/BasicFilters/otbMeanShiftImageFilter2.h
@@ -27,6 +27,52 @@
 namespace otb
 {
 
+template<class TInputImage, class TOutputJointImage>
+class SpatialRangeJointDomainTransform
+{
+public:
+  typedef double RealType;
+
+  SpatialRangeJointDomainTransform() {}
+  ~SpatialRangeJointDomainTransform() {}
+
+  inline typename TOutputJointImage::PixelType operator() (const typename TInputImage::PixelType & inputPixel, const typename TInputImage::IndexType & index)
+  {
+    typename TOutputJointImage::PixelType jointPixel;
+    jointPixel.SetSize(ImageDimension + m_NumberOfComponentsPerPixel);
+
+    for(unsigned int comp = 0; comp < ImageDimension; comp++)
+      {
+      jointPixel[comp] = index[comp] / m_SpatialBandwidth;
+      }
+    for(unsigned int comp = 0; comp < m_NumberOfComponentsPerPixel; comp++)
+      {
+      jointPixel[ImageDimension + comp] = inputPixel[comp] / m_RangeBandwidth;
+      }
+    return jointPixel;
+  }
+
+  void Initialize(unsigned int _ImageDimension, unsigned int _m_NumberOfComponentsPerPixel, RealType _m_SpatialBandwidth, RealType _m_RangeBandwidth)
+  {
+    ImageDimension = _ImageDimension;
+    m_NumberOfComponentsPerPixel = _m_NumberOfComponentsPerPixel;
+    m_SpatialBandwidth = _m_SpatialBandwidth;
+    m_RangeBandwidth = _m_RangeBandwidth;
+    m_OutputSize = ImageDimension + m_NumberOfComponentsPerPixel;
+  }
+
+  unsigned int GetOutputSize()
+  {
+    return m_OutputSize;
+  }
+
+private:
+  unsigned int ImageDimension;
+  unsigned int m_NumberOfComponentsPerPixel;
+  unsigned int m_OutputSize;
+  RealType m_SpatialBandwidth;
+  RealType m_RangeBandwidth;
+};
 
 /** \class MeanShiftImageFilter2
  *
diff --git a/Code/BasicFilters/otbMeanShiftImageFilter2.txx b/Code/BasicFilters/otbMeanShiftImageFilter2.txx
index b99a9463f88269b591b607965909eb50774e489a..2bd5d7a4c3815b10a0640956c98fd87c947f31b4 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter2.txx
+++ b/Code/BasicFilters/otbMeanShiftImageFilter2.txx
@@ -23,6 +23,7 @@
 
 #include "itkImageRegionConstIteratorWithIndex.h"
 #include "itkImageRegionIterator.h"
+#include "otbUnaryFunctorWithIndexWithOutputSizeImageFilter.h"
 #include "otbMacro.h"
 
 #include "itkProgressReporter.h"
@@ -293,6 +294,18 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
 
   m_NumberOfComponentsPerPixel = this->GetInput()->GetNumberOfComponentsPerPixel();
 
+
+  typedef SpatialRangeJointDomainTransform<InputImageType, RealVectorImageType> FunctionType;
+  typedef otb::UnaryFunctorWithIndexWithOutputSizeImageFilter<InputImageType, RealVectorImageType, FunctionType> JointImageFunctorType;
+
+  typename JointImageFunctorType::Pointer jointImageFunctor = JointImageFunctorType::New();
+
+  jointImageFunctor->SetInput(inputPtr);
+  jointImageFunctor->GetFunctor().Initialize(ImageDimension, m_NumberOfComponentsPerPixel, m_SpatialBandwidth, m_RangeBandwidth);
+  jointImageFunctor->Update();
+  m_JointImage = jointImageFunctor->GetOutput();
+
+/*
   // Allocate the joint domain image
   m_JointImage = RealVectorImageType::New();
   m_JointImage->SetNumberOfComponentsPerPixel(ImageDimension + m_NumberOfComponentsPerPixel);
@@ -325,7 +338,7 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
     ++inputIt;
     ++jointIt;
     }
-
+*/
 }