C++ 提取纹理特征c++;

C++ 提取纹理特征c++;,c++,opencv,feature-extraction,C++,Opencv,Feature Extraction,我试图通过使用周围像素的灰度值为图像的每个像素提取特征向量: 标记为黑色的像素是使用的像素,因为其他像素对于稍后使用的SVM结果是冗余的 目前使用此代码: vector<Histogram*> texture_based(image_file* image) { int cat; Mat img = cvLoadImage(image->getName().c_str(), CV_LOAD_IMAGE_GRAYSCALE); Mat img_b(img.rows +

我试图通过使用周围像素的灰度值为图像的每个像素提取特征向量: 标记为黑色的像素是使用的像素,因为其他像素对于稍后使用的SVM结果是冗余的

目前使用此代码:

vector<Histogram*> texture_based(image_file* image) {
  int cat;
  Mat img = cvLoadImage(image->getName().c_str(), CV_LOAD_IMAGE_GRAYSCALE);
  Mat img_b(img.rows + 12, img.cols + 12, img.depth());

copyMakeBorder(img, img_b, 6, 6, 6, 6, IPL_BORDER_CONSTANT, cvScalarAll(0));

vector<Histogram*> result;

for(int i = 6; i < img_b.rows - 6; ++i) {
    for(int j = 6; j < img_b.cols - 6; ++j) {
        Mat hist = Mat::zeros(1, 49, CV_32FC1);
        cat = 0;
        hist.at<float>(0, 0) = (float)img_b.at<char>(i - 6, j - 6);
        hist.at<float>(0, 1) = (float)img_b.at<char>(i - 5, j - 5);
        hist.at<float>(0, 2) = (float)img_b.at<char>(i - 4, j - 4);
        hist.at<float>(0, 3) = (float)img_b.at<char>(i - 3, j - 3);
        hist.at<float>(0, 4) = (float)img_b.at<char>(i - 2, j - 2);
        hist.at<float>(0, 5) = (float)img_b.at<char>(i - 1, j - 1);
        hist.at<float>(0, 6) = (float)img_b.at<char>(i, j);
        hist.at<float>(0, 7) = (float)img_b.at<char>(i + 1, j + 1);
        hist.at<float>(0, 8) = (float)img_b.at<char>(i + 2, j + 2);
        hist.at<float>(0, 9) = (float)img_b.at<char>(i + 3, j + 3);
        hist.at<float>(0, 10) = (float)img_b.at<char>(i + 4, j + 4);
        hist.at<float>(0, 11) = (float)img_b.at<char>(i + 5, j + 5);
        hist.at<float>(0, 12) = (float)img_b.at<char>(i + 6, j + 6);
        hist.at<float>(0, 13) = (float)img_b.at<char>(i + 6, j - 6);
        hist.at<float>(0, 14) = (float)img_b.at<char>(i + 5, j - 5);
        hist.at<float>(0, 15) = (float)img_b.at<char>(i + 4, j - 4);
        hist.at<float>(0, 16) = (float)img_b.at<char>(i + 3, j - 3);
        hist.at<float>(0, 17) = (float)img_b.at<char>(i + 2, j - 2);
        hist.at<float>(0, 18) = (float)img_b.at<char>(i + 1, j - 1);
        hist.at<float>(0, 19) = (float)img_b.at<char>(i - 1, j + 1);
        hist.at<float>(0, 20) = (float)img_b.at<char>(i - 2, j + 2);
        hist.at<float>(0, 21) = (float)img_b.at<char>(i - 3, j + 3);
        hist.at<float>(0, 22) = (float)img_b.at<char>(i - 4, j + 4);
        hist.at<float>(0, 23) = (float)img_b.at<char>(i - 5, j + 5);
        hist.at<float>(0, 24) = (float)img_b.at<char>(i - 6, j + 6);
        hist.at<float>(0, 25) = (float)img_b.at<char>(i, j - 6);
        hist.at<float>(0, 26) = (float)img_b.at<char>(i, j - 5);
        hist.at<float>(0, 27) = (float)img_b.at<char>(i, j - 4);
        hist.at<float>(0, 28) = (float)img_b.at<char>(i, j - 3);
        hist.at<float>(0, 29) = (float)img_b.at<char>(i, j - 2);
        hist.at<float>(0, 30) = (float)img_b.at<char>(i, j - 1);
        hist.at<float>(0, 31) = (float)img_b.at<char>(i, j + 1);
        hist.at<float>(0, 32) = (float)img_b.at<char>(i, j + 2);
        hist.at<float>(0, 33) = (float)img_b.at<char>(i, j + 3);
        hist.at<float>(0, 34) = (float)img_b.at<char>(i, j + 4);
        hist.at<float>(0, 35) = (float)img_b.at<char>(i, j + 5);
        hist.at<float>(0, 36) = (float)img_b.at<char>(i, j + 6);
        hist.at<float>(0, 37) = (float)img_b.at<char>(i - 6, j);
        hist.at<float>(0, 38) = (float)img_b.at<char>(i - 5, j);
        hist.at<float>(0, 39) = (float)img_b.at<char>(i - 4, j);
        hist.at<float>(0, 40) = (float)img_b.at<char>(i - 3, j);
        hist.at<float>(0, 41) = (float)img_b.at<char>(i - 2, j);
        hist.at<float>(0, 42) = (float)img_b.at<char>(i - 1, j);
        hist.at<float>(0, 43) = (float)img_b.at<char>(i + 1, j);
        hist.at<float>(0, 44) = (float)img_b.at<char>(i + 2, j);
        hist.at<float>(0, 45) = (float)img_b.at<char>(i + 3, j);
        hist.at<float>(0, 46) = (float)img_b.at<char>(i + 4, j);
        hist.at<float>(0, 47) = (float)img_b.at<char>(i + 5, j);
        hist.at<float>(0, 48) = (float)img_b.at<char>(i + 6, j);
        if(image->inAnyRec(i, j))
            cat = 1;

        Mat_<float> new_hist = hist;
        Histogram* t = new Histogram(&new_hist, cat);
        result.push_back(t);
    }
}

return result;
}
基于向量纹理的(图像文件*图像){ int-cat; Mat img=cvLoadImage(image->getName().c\u str(),CV\u LOAD\u image\u灰度); Mat img_b(img.rows+12,img.cols+12,img.depth()); copyMakeBorder(img,img_b,6,6,6,6,IPL_BORDER_常量,cvScalarAll(0)); 矢量结果; 对于(int i=6;iinAnyRec(i,j)) cat=1; Mat_uuNew_uHist=历史; 直方图*t=新直方图(&new_hist,cat); 结果:推回(t); } } 返回结果; } 其中image_file*指针指向包含图像信息的类。
我想知道是否有更快的方法来完成这项工作。

您可以在4次传递中计算操作;每个将初始化12(或13)个元素的向量,向东、南、东北或东南移动一个像素,并从向量中仅替换一个像素。这还需要一次初始化所有直方图向量(宽度-12)*(高度-12),49

一个支持的选项是将原始图像旋转/倾斜为四个数组——如果在此时执行char->float转换有意义,则必须对其进行分析

a b c d   -->  a e i  -->  a f k  >  i f c
e f g h        b f j       b g l     j g d
i j k l        c g k      
               d h l
从这些新数组中,内存读取模式/缓存位置可能会有所不同。

可以在代码中的某个地方尝试cv::filter2D()或cv::bitwise_和()。