在我的代码我遇到局部二进制模式结果的问题 [英] In My Code I Have A Problem With Local Binary Pattern Results

查看:67
本文介绍了在我的代码我遇到局部二进制模式结果的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些图像这些图像是使用统一的局部二进制模式和空间直方图预先分配然后我把结果自组织代码旨在增强SOM的结果当我运行lbp代码我有一些带有少量数据的黑色图像,精度更差,这里有任何人都有这个组合代码或者我如何增强结果的想法



这是代码制服



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

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






spatialhist code

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;
}

推荐答案

最好和现实世界的方式是你自己制作一些样本图片,其结果如下很明显。所以你可以找到你的错误。



你几乎没有机会调试你的代码...; - )
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... ;-)


这篇关于在我的代码我遇到局部二进制模式结果的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆