得到LBP特徵值圖

來源:互聯網
上載者:User

標籤:影像處理   algorithm   opencv   lbp   

// 得到 LBP紋理特徵值圖// 參數:// src 為單通道灰階圖// dst 為靶心圖表// 傳回值:// 返回ture 表示運行正常// 返回false 表示運行出錯bool GetLBPFeatureImage(IplImage *src, IplImage *dst){if (! src || ! dst) return false;// 擷取映像資訊const int height = src->height;const int width  = src->width;const int widthStep = src->widthStep;const int channels  = src->nChannels;  // 通道數const uchar * data  = (uchar *)src->imageData;if (channels != 1 || data == NULL){return false;}// 相鄰點的八個方位const intdirect[8][2] = { {-1, 0}, {-1, 1},                              {0,  1}, {1,  1},           {1,  0}, {1, -1},                              {0, -1}, {-1,-1} };// 處理中的過程圖const int temHeight = src->height + 2;const int temWidth  = src->width + 2;const int temWidthStep = src->widthStep + 2;const int temChannels  = src->nChannels;  // 通道數int *imgTem = new int[temHeight * temWidthStep];// 映像大小往外擴充一個單位像素int row = 0, col = 0;imgTem[row * temWidthStep + col] = (int)data[0 * widthStep + 0];row = 0; col = width + 1;imgTem[row * temWidthStep + col] = (int)data[0 * widthStep + (width-1)];row = height + 1; col = 0;imgTem[row * temWidthStep + col] = (int)data[(height - 1) * widthStep + 0];row = height + 1; col = width + 1;imgTem[row * temWidthStep + col] = (int)data[(height - 1) * widthStep + (width-1)];row = 0;for (col = 1; col < width + 1; col ++){imgTem[row * temWidthStep + col] = (int)data[0 * widthStep + (col - 1)];}row = height + 1;for (col = 1; col < width + 1; col ++){imgTem[row * temWidthStep + col] = (int)data[(height - 1) * widthStep + (col - 1)];}col = 0;for (row = 1; row < height + 1; row ++){imgTem[row * temWidthStep + col] = (int)data[(row - 1) * widthStep + 0];}col = width + 1;for (row = 1; row < height + 1; row ++){imgTem[row * temWidthStep + col] = (int)data[(row - 1) * widthStep + (width - 1)];}for (row = 1; row < height + 1; row ++){for (int col = 1; col < width + 1; col ++){imgTem[row * temWidthStep + col] = (int)data[(row - 1) * widthStep + (col - 1)];}}// 求LBP 特徵值for (row = 1; row < height + 1; row ++){for (col = 1; col < width + 1; col ++){int bin = 0;    // 存放一個8位位元for (int k = 0; k < 8; k ++){int valueCenterPoint = imgTem[row * temWidthStep + col]; // 中心像素值int valueDirectPoint = imgTem[ (row + direct[k][0]) * temWidthStep + col + direct[k][1] ]; // 相鄰點的像素值int b = valueCenterPoint >  valueDirectPoint ? 0 : 1;bin += b * (int)pow(2, k); // 獲得一個8位位元}dst->imageData[(row - 1) * widthStep + (col - 1)] = (char)bin;}}return true;}

得到LBP特徵值圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.