Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a number of images these images are prepossessed using uniform local binary pattern and spatial histogram then i take the result to self organizing code aimed to enhance the result of SOM when i run lbp code i have a black images with a few data and the accuracy is worse any one here has this combined code or an idea of how i enhance the result

this is the code of uniform

C++
int LBPFeatures::countSetBits(int code)
{
  int count=0;
  int v=code;
  for(count=0;v;count++)
  {
  v&=v-1; //clears the LSB
  }
  return count;
}

int LBPFeatures::rightshift(int num, int shift)
{
    return (num >> shift) | ((num << (8 - shift)&0xFF));
}


bool LBPFeatures::checkUniform(int code)
{
    int b = rightshift(code,1);
  //int d = code << 1;
  int c = code ^ b;
  //d= code ^d;
  int count=countSetBits(c);
  //int count1=countSetBits(d);
  if (count <=2 )
      return true;
  else
      return false;
}


void LBPFeatures::initUniform( int check)
{

    lookup.resize(256);
    int index=0;

    for(int i=0;i<=255;i++)
    {
        bool status=checkUniform(check);
        if(status==true)
        {
            lookup[i]=index;
            index++;
        }
        else
        {
            lookup[i]=59;
        }
    }
    spatialhist Hist;
Hist.initHistogram();

}


void LBPFeatures::computeuniformlbp(Mat image,Mat &dst)
{
    uchar *ptr=image.data;
    image.copyTo(dst);
    uchar *optr=dst.data;
    int width=image.cols;
    int height=image.rows;

    for(int i=1;i<height-1;i++)
    {
        for(int j=1;j<width-1;j++)
        {
            int center=(uchar)ptr[j+i*width];
            unsigned char code=0;

            //for(int k=7;k>=0;k++)

            code|=((uchar)ptr[(j-1)+(i-1)*width] >=center)<<7;
            code|=((uchar)ptr[j+(i-1)*width] >=center)<<6 ;
            code|=((uchar)ptr[(j+1)+(i-1)*width] >=center)<<5 ;
            code|=((uchar)ptr[(j+1)+(i)*width] >=center)<<4 ;
            code|=((uchar)ptr[(j+1)+(i+1)*width] >=center)<<3 ;
            code|=((uchar)ptr[j+(i+1)*width] >=center)<<2 ;
            code|=((uchar)ptr[j-1+(i+1)*width] >=center)<<1 ;
            code|=((uchar)ptr[j-1+(i)*width] >=center)<<0 ;


            //heck if the code is uniform code
            //encode only if it is a uniform code else
            //assign it a number 255
            initUniform(code);
            //lookup.push_back(code);
            optr[j+i*width]=lookup[code];

        }
    }

}



spatialhist code

C++
spatialhist::spatialhist(){
     sizeb=59;
}

Mat spatialhist::computeHistogram(Mat& cell)
{
     Mat histogram;
  histogram=  hist.BuildHistogram(cell);

    return histogram;

}


void spatialhist::initHistogram()
{
    vector<int> channel;
    channel.push_back(0);
    hist.setChannel(channel);
    vector<int> size;
    size.push_back(sizeb);
    hist.setHistSize(size);
    vector<float> range;
    range.push_back(0);
    range.push_back(59);
    hist.setRange(range);

}



vector<float> spatialhist::spatialHistogram( const Mat& lbpImage, const Size& grid)
{
    vector<float> histograms;
    histograms.resize(grid.width*grid.height*sizeb);
    int width=lbpImage.cols/grid.width;
    int height=lbpImage.rows/grid.height;
    int cnt=0;
    //#pragma omp parallel for
    for(int i=0;i<grid.height;i++)
    {
        for(int j=0;j<grid.width;j++)
        {
            Mat cell=lbpImage(Rect(j*width,i*height,width,height));
            Mat cell_hist=computeHistogram(cell);
            histogramsimage.push_back(cell_hist);
            //imshow("FFF",cell_hist);

            Mat tmp_feature;
           Mat feature =cell_hist.reshape(1,1);
            feature.convertTo(tmp_feature,CV_32FC1);

            float * ptr=tmp_feature.ptr<float>(0);
            for(int k=0;k<tmp_feature.cols-1;k++)
            {
                if(ptr[k]==0)
                    ptr[k]=1.0/sizeb;
                histograms[(cnt*sizeb)+k]=ptr[k];
              //  cerr << ptr[k] << endl;
            }
            cnt++;
        }

    }

    histogramsimage.reshape(1,1);
    return histograms;
}
Posted
Updated 10-Jun-14 1:29am
v6
Comments
phil.o 9-Jun-14 5:51am    
Without seeing the code manipulating the original image, we are only bound to guess.
Best one would be your implementation of "uniform local binary pattern" and "spatial histogram" algorithms.

1 solution

The best and "real world" way is that you make some sample pictures for yourself in which the results are obvious. So you can find your bugs.

You have little chances that anybody debugs your code... ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900