diff --git a/app/otbPatchesSelection.cxx b/app/otbPatchesSelection.cxx
index 669f7ea65c150ffb275dec1f1365f6fd28f7adca..03a22023b404fa973602899286babd702eca7bc7 100644
--- a/app/otbPatchesSelection.cxx
+++ b/app/otbPatchesSelection.cxx
@@ -297,7 +297,7 @@ public:
    * Allocate a std::vector of sample bundle
    */
   std::vector<SampleBundle>
-  AllocateSamples()
+  AllocateSamples(unsigned int nbOfClasses = 2)
   {
     // Nb of samples (maximum)
     const UInt8ImageType::RegionType entireRegion = m_MorphoFilter->GetOutput()->GetLargestPossibleRegion();
@@ -308,7 +308,6 @@ public:
     maxNbOfSamples *= maxNbOfRows;
 
     // Nb of classes
-    const unsigned int nbOfClasses = GetParameterInt("strategy.balanced.nclasses");
     SampleBundle initSB(nbOfClasses);
     std::vector<SampleBundle> bundles(maxNbOfSamples, initSB);
 
@@ -357,7 +356,7 @@ public:
 
     otbAppLogINFO("Computing samples distribution...");
 
-    std::vector<SampleBundle> bundles = AllocateSamples();
+    std::vector<SampleBundle> bundles = AllocateSamples(GetParameterInt("strategy.balanced.nclasses"));
 
     // Patch size
     UInt8ImageType::SizeType patchSize;