Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

for anyone looking at this, the solution i ultimately used, was just to use the non uniform bins input in the calcHist function. First i looked through and matched the input values to the nearest stored value.

    void textonFind(Mat& clus, Mat dictionary){
      if(clus.empty() || dictionary.empty()){
        ERR("Texton Find inputs were empty.");
        exit(-1);
      }
      // Loop through input centers
      for(int h=0;h<clus.rows;h++){
        float distance = 0.0, nearest = 0.0;

        distance = abs(dictionary.at<float>(0,0) - clus.at<float>(h,0));
        nearest = dictionary.at<float>(0,0);

        // Compare current centre with all values in texton dictionary
        for(int k = 0; k < dictionary.rows; k++){
          if(abs(dictionary.at<float>(k,0) - clus.at<float>(h,0)) < distance){
            nearest = dictionary.at<float>(k,0);
            distance = abs(dictionary.at<float>(k,0) - clus.at<float>(h,0));
          }
        }
        // Replace input Center with closest Texton Center
        clus.at<float>(h,0) = nearest;
      }
    }

Then to generate the bin ranges i looped through the original values i wanted to match the new values to and simply added 0.00001 this acted as the upper exclusion limit putting any values which were above this in the next bin, as i knew all the possible values i didn't need to find the nearest as that was already done.

    // Create bins for each textonDictionary Value
    void binLimits(vector<float>& tex){
      dicDEBUG("inside binLimits", 0);
      vector<float> bins;
      bins.push_back(0);
      for(int i = 0;i <= tex.size()-1;i++){
          bins.push_back(tex[i] + 0.00001);
      }
      bins.push_back(256);
      for(int i=0;i<bins.size();i++)
        cout << "texDict: " << i << ": "<< tex[i] << " becomes: " << bins[i+1] << endl;
      tex.clear();
      tex = bins;
    }

The above code isn't necessarily pretty but it works in case anyone has a similar problem.