顏色相關圖(Color Correlogram)

來源:互聯網
上載者:User


顏色相關圖的參考文獻:

        [1] Greg Pass, RaminZabih. Comparing images using color coherence vectors.

代碼如下:

/************************************************************************//*作用:計算顏色相關圖輸入:img---源映像,計算的第channel通道的顏色矩輸出:浮點型數組,顏色相關圖的維數為64維傳回值:0   計算成功1   圖片為空白,計算失敗2參數指標correlogram沒有分配記憶體3   圖片通道不是1,目前只處理單通道圖片,計算失敗*//************************************************************************/int calColorCorrelogram(const IplImage * img,double * correlogram){if(NULL == img)return 1;if(NULL == correlogram)return 2;if(img->nChannels > 1)return 3;//產生一個數組,每個點的範圍是0-7int width = img->width;int height = img->height;int * mark = new int[width * height]; int step = img->widthStep/sizeof(uchar);uchar * data = (uchar *)img->imageData;for (int i = 0;i < height;++i)for (int j = 0;j < width;++j)mark[i * width + j] = int(8 * data[i * width + j]  * 1.0 /256); //計算相關圖 DISTANCE = 8int grade,hist;int sum = 0;for (int i = 0;i < height - DISTANCE + 1;++i){for (int j = 0;j < width - DISTANCE + 1;++j){//擷取當前點的灰階級,目前分8個等級 hist = mark[i * width + j];for (int k = 1;k < DISTANCE;k++){for (int r = 1;r < DISTANCE;r++){if(mark[(i + k) * width + j + r] == hist){grade = k > r ? k : r;//擷取距離---水平與垂直距離中較大的correlogram[hist * DISTANCE + grade - 1]++;sum++;}}}}}if(sum <= 0)return 1;//計算特徵向量 GRAM_SIZE = 64for(int i = 0;i < GRAM_SIZE;i++)correlogram[i] = correlogram[i] / sum;delete[] mark;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.