[æ©æ¢°å¦ç¿] bayon+LSHIKITã使ã£ã¦ç»åã¯ã©ã¹ã¿ãªã³ã°
bayonを使って画像からbag-of-keypointsを求める - のんびり読書日記ã®è¨äºãèªãã§ãã¯ã©ã¹ã¿ãªã³ã°ãè¡ãéã®å ¥åãã¼ã¿ãä½ãããã«æç®[1]ã«ããæ¹æ³ãå©ç¨ã§ããã¨æã£ã¦å®é¨ãã¦ã¿ãã
å±æç¹å¾´éãæã£ããã¼ã¿ã®åæ±ã
ç»åãã¼ã¿ã®åé¡ãªã©ãè¡ãéã«SIFTã®ãããªç»åä¸ã®ç¹å¾´ç¹(keypoint)ãæ½åºããã¨ãããã¨ãããè¡ãããã
ä¾ãã°SIFTãç¨ããå ´åã¯åkeypointã¯128次å
ã®ãã¯ãã«ã¨ãªããç»åãã¨ã«ããã¤ãã®keypointãæ½åºããããããã§æ½åºãããkeypointã®æ°ã¯ç»åãã¨ã«ç°ãªãããã®ãããç»åéã®é¡ä¼¼æ§ãæ¯è¼ããã®ã¯å°é£ã§ããã
ããã«å¯¾ããã¢ããã¼ãã¨ãã¦ã¯ä¸ã¤ã¯ç»åä¸ã®ç¹å¾´ç¹å士ã®å
¨å¯¾æ¯è¼ãè¡ãããããã¯ãããã³ã°ãã¨ãã¨ããæ¹æ³ãæãããããããã¯è¨ç®éãé常ã«å¤§ããã
å¥ã®æ¹æ³ã¨ãã¦ãã¹ãã°ã©ã ãå©ç¨ããã¨ããæ¹æ³ããããããã¯åç¹å¾´ç¹ãéååãã¦ç»åå
¨ä½ãä¸ã¤ã®ç¹å¾´ãã¯ãã«ã«è½ã¨ãã¨ãããã®ã§ããããã®ç¹å¾´ãã¯ãã«ã¯éååããç¹å¾´ç¹ã®é »åº¦ã®ãã¹ãã°ã©ã ã¨ãã¦è¡¨ç¾ãããããããè¡ãä¸ã¤ã®æ¹æ³ã¨ãã¦ã¯[2]ã§ç´¹ä»ããã¦ããVisual Wordã®æ¹æ³ãããã
ããä¸ã¤ã®æ¹æ³ã¨ãã¦ã¯[1]ã§ææ¡ããã¦ããLSHãç¨ãããã¹ãã°ã©ã ã®æ§ææ³ãããã
LSHãç¨ãããã¹ãã°ã©ã ã®æ§æ
ç°¡åã«[1]ã®ææ³ãç´¹ä»ãããLSHãä½ãã«ã¤ãã¦ã¯[3]ãªã©ã確èªãã¦ãããã¨ãã¦ãããã§ã¯ç¹å¾´ç¹ãBãããã«ããã·ã³ã°ããé¢æ°ããããä¼¼ãç¹å¾´ç¹ã¯é«ã確çã§åãããã·ã¥å¤ãã¨ããããªé¢æ°hãæ§æã§ãã¦ããã¨ããå ã§è°è«ãé²ããã
ç»åä¸ã®åç¹å¾´ç¹ã«å¯¾ãã¦LSHãç¨ãã¦ããã·ã³ã°ãããããã«ãã£ã¦å¾ãããããã·ã¥é¢æ°ã®å¤ã¯[0,2^B)ã®ç¯å²ãåããåå¤ã®é »åº¦(ãã¹ãã°ã©ã )ãè¨ç®ãããã¨ã«ãã£ã¦2^B次å ã®ç¹å¾´ãã¯ãã«ãçæãããããããã®ãã¹ãã°ã©ã ãç¬ç«ã«Nåçæãã¦é£çµãããã¨ã«ãã£ã¦N * 2^B次å ã®ç¹å¾´ãã¯ãã«ã¨ãã¦1æã®ç»åã表ç¾ãããã¾ããç»åã«key-pointãå°ãªãã¨ãã«ãã¹ãã°ã©ã ã«ä½¿ãããªãå¤ãå¤ãåºã¦ãã¦ãã¾ãã®ã§ãã¹ãã°ã©ã ã®ä½ææã«ç¬ç«ãªMåã®ããã·ã¥é¢æ°ãé©ç¨ãã¦ãã®å¤ã®é »åº¦ã足ãã¨ããæä½(Folding)ãå ããã
ãããã®æä½ãè¡ããã¨ã«ãããç¹å¾´ç¹ã®éåãç¹å¾´ç¹ã®åæ°ã«ãããªãä¸ã¤ã®N * 2^B次å
ã®ç¹å¾´ãã¯ãã«ã¨ãã¦è¡¨ç¾ã§ãããã¨ã¯é常ã®ãã¯ãã«ãã¼ã¿ãæ±ããã¼ã«ãé©ç¨ãããã¨ãã§ããã
å®è£
[1]ã®ä½è
ãå
¬éãã¦ããLSHKITã¨ãããã¼ã«ããããããã«ä¸ã§è¿°ã¹ããã¹ãã°ã©ã ãç¨ããæ§ææ³ãè¼ã£ã¦ããã®ã§å®è£
ãã¦ã¿ããããã°ã©ã ã®åãã¨ãã¦ã¯æ¨æºå
¥åããç»åãã¡ã¤ã«ã®ãã¹ãåãã¨ãã¨ããã®ãã¹ã«é¢ãããã¹ãã°ã©ã ãbayonã§ç¨ãããã¨ã®ã§ããå½¢å¼ã«ãã¦æ¨æºåºåã«åºåããã¨ãããã®ã«ãªã£ã¦ã¾ãã[2]ã®è¨äºã¨æ¯è¼ããã¨Visual Wordãbayonã§ã¯ã©ã¹ã¿ãªã³ã°ãè¡ãç¹å®ãã¦ãbag-of-keypointsã«åºåã¨ããé¨åããªããªã£ã¦ãå
¥åç»åããç´æ¥ãã¹ãã°ã©ã ãçæãã¦ããã¨ãåããã
å©ç¹ã¨ãã¦ã¯å
¥åã®ç»åã®ã¿ã§ãã¹ãã°ã©ã ãä½ããã®ã§[2]ã§è¿°ã¹ããã¦ãããããªVisual Wordã®ç¹å®ã«ã¡ã¢ãªã足ããªããªãã¨ãããã¨ããªããã¨ãæããããã
#include <iostream> #include <string> #include <vector> #include <numeric> #include <algorithm> #include <unistd.h> #include <highgui.h> #include <lshkit.h> extern "C"{ #include "sift.h" #include "imgfeatures.h" #include "utils.h" } using namespace std; using namespace lshkit; typedef Repeat<ThresholdingLsh> MyLSH; typedef Histogram<MyLSH> MyHistogram; int main(){ string filePath; while(getline(cin , filePath)){ // load image IplImage * img = cvLoadImage(filePath.c_str(), 1); if(!img){ cerr << "unable to load image from " << filePath; continue; } // extract SIFT Features struct feature * features; int numberOfKeypoints = sift_features( img , &features); vector < vector<float> > sift_fs_vector( numberOfKeypoints); for(int i = 0 ; i < numberOfKeypoints ; ++i){ int d = features[i].d; vector<float> fs_v(d); for(int j = 0 ; j < d ; ++j){ fs_v[j] = features[i].descr[j]; } sift_fs_vector[i] = fs_v; } free(features); cvReleaseImage(&img); // create Histogram MyLSH::Parameter param; param.repeat = 8; // repeat 8 times, produce 8 bits. param.dim = 128; param.min = 0.0; param.max = 255.0; // Parameters are set for SIFT features. DefaultRng rng; unsigned N = 10, M = 10; MyHistogram hist; hist.reset(M, N, param, rng); float * output = new float[hist.dim()]; hist.zero(output); for(int i = 0 ; i < sift_fs_vector.size() ; ++i){ hist.add(output , &sift_fs_vector[i][0]); } cout << filePath; for(int i = 0 ; i < hist.dim() ; ++i){ if(output[i]){ cout << "\t" << i << "\t" << output[i]; } } cout << endl; delete[] output; } return 0; }
ã¯ã©ã¹ã¿ãªã³ã°
æå¾ã«bayonãç¨ãã¦ã¯ã©ã¹ã¿ãªã³ã°ãå®è¡ãã¦ã¿ããã³ãã³ãã¯[2]ã¨åæ§ã«
bayon -n 500 --idf data/bok.tsv > data/cluster.tsv
ã¨ããã
å¾ãããã¯ã©ã¹ã¿ã®ããã¤ãã示ãã1çªãã¨2çªãã¯ãããªãã®ã¾ã¨ã¾ããè¦ãã¦ãããã3çªç®ã¯ããã¨ãã¡ãã£ã¨ãã¦ãã¦ã¯ã©ã¹ã¿ãªã³ã°ãã¡ããã¨ã§ãã¦ããã¨ã¯ãããªãã
LSHã使ã£ã¦ãã¹ãã°ã©ã ãæ§æããé¨åã¯çµæ§ãã©ã¡ã¼ã¿ãããã¤ããããããã®é¨åã«é¢ãããã¥ã¼ãã³ã°ã¨bayon以å¤ã®ã¯ã©ã¹ã¿ãªã³ã°ææ³ã試ããã¨ãèããããèå³æ·±ããã¾ããè«æã§ã¯SIFTã§ã¯ãªãPCA SIFTã¨ãããã®ãç¨ãã¦ããã®ã§ããã使ããã¨ãèããããã
ãã¨ã¯SVMãªã©ãå©ç¨ããå¤å¥ãªã©ã¯ã©ã¹ã¿ãªã³ã°ä»¥å¤ã®åé¡ã解ãã®ãé¢ç½ããããããªãã
åèæç®
- [1] Wei Dong, Zhe Wang, Moses Charikar, Kai Li. Efficiently Matching Sets of Features with Random Histograms. In Proceedings of the 16th ACM International Conference on Multimedia. Vancouver, Canada. October 2008. pdf,ppt
- [2] bayonを使って画像からbag-of-keypointsを求める - のんびり読書日記
- [3] M. S. Charikar. Similarity Estimation Techniques from Rounding Algorithms. In STOC '02, 2002.