簡介
BRISK算法是2011年ICCV上《BRISK:Binary Robust Invariant Scalable Keypoints》文章中,提出來的一種特征提取算法,也是一種二進制的特征描述算子。
它具有較好的旋轉不變性、尺度不變性,較好的魯棒性等。在圖像配准應用中,速度比較:SIFT<SURF<BRISK<FREAK<ORB,在對有較大模糊的圖像配准時,BRISK算法在其中表現最為出色。
BRISK算法
特征點檢測
BRISK算法主要利用FAST9-16進行特征點檢測(為什么是主要?因為用到一次FAST5-8),可參見博客:FAST特征點檢測算法。要解決尺度不變性,就必須在尺度空間進行特征點檢測,於是BRISK算法中構造了圖像金字塔進行多尺度表達。
建立尺度空間
構造n個octave層(用ci表示)和n個intra-octave層(用di表示),文章中n=4,i={0,1,...,n-1}。假設有圖像img,octave層的產生:c0層就是img原圖像,c1層是c0層的2倍下采樣,c2層是c1層的2倍下采樣,以此類推。intra-octave層的產生:d0層是img的1.5倍下采樣,d1層是d0層的2倍下采樣(即img的2*1.5倍下采樣),d2層是d1層的2倍下采樣,以此類推。
則ci、di層與原圖像的尺度關系用t表示為:,
ci、di層與原圖像大小關系為:
由於n=4,所以一共可以得到8張圖,octave層之間尺度(縮放因子)是2倍關系,intra-octave層之間尺度(縮放因子)也是2倍關系。
特征點檢測
對這8張圖進行FAST9-16角點檢測,得到具有角點信息的8張圖,對原圖像img進行一次FAST5-8角點檢測(當做d(-1)層,虛擬層),總共會得到9幅有角點信息的圖像。
非極大值抑制
對這9幅圖像,進行空間上的非極大值抑制(同SIFT算法的非極大值抑制):特征點在位置空間(8鄰域點)和尺度空間(上下層2x9個點),共26個鄰域點的FAST的得分值要最大,否則不能當做特征點;此時得到的極值點還比較粗糙,需要進一步精確定位。
亞像素插值
進過上面步驟,得到了圖像特征點的位置和尺度,在極值點所在層及其上下層所對應的位置,對FAST得分值(共3個)進行二維二次函數插值(x、y方向),得到真正意義上的得分極值點及其精確的坐標位置(作為特征點位置);再對尺度方向進行一維插值,得到極值點所對應的尺度(作為特征點尺度)。
特征點描述
高斯濾波
現在,我們得到了特征點的位置和尺度(t)后,要對特征點賦予其描述符。均勻采樣模式:以特征點為中心,構建不同半徑的同心圓,在每個圓上獲取一定數目的等間隔采樣點(所有采樣點包括特征點,一共N個),由於這種鄰域采樣模式會引起混疊效應,所以需要對同心圓上的采樣點進行高斯濾波。
采樣模式如下圖,藍圈表示;以采樣點為中心,為方差進行高斯濾波,濾波半徑大小與高斯方差的大小成正比,紅圈表示。最終用到的N個采樣點是經過高斯平滑后的采樣點。下圖是t=1時的。(文章中:N=60)
局部梯度計算
由於有N個采樣點,則采樣點兩兩組合成一對,共有N(N-1)/2鍾組合方式,所有組合方式的集合稱作采樣點對,用集合表示,其中像素分別是
、
,δ表示尺度。用
表示特征點局部梯度集合,則有:
定義短距離點對子集、長距離點對子集(L個):
其中,,
,t是特征點所在的尺度。
現在要利用上面得到的信息,來計算特征點的主方向(注意:此處只用到了長距離子集),如下:
特征描述符
要解決旋轉不變性,則需要對特征點周圍的采樣區域進行旋轉到主方向,旋轉后得到新的采樣區域,采樣模式同上。BRISK描述子是二進制的特征,由采樣點集合可得到N(N-1)/2對采樣點對,就可以得到N(N-1)/2個距離的集合(包含長、短距離子集),考慮其中短距離子集中的512個短距離點對,進行二進制編碼,判斷方式如下:
其中,帶有上標,表示經過旋轉a角度后的,新的采樣點。由此可得到,512Bit的二進制編碼,也就是64個字節(BRISK64)。
匹配方法
漢明距離進行比較,與其他二進制描述子的匹配方式一樣。
實驗
opencv代碼
- #include <cv.h>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/core/core.hpp>
- #include <opencv2/nonfree/features2d.hpp>
- #include <opencv2/nonfree/nonfree.hpp>
- #include <Windows.h>
- using namespace cv;
- using namespace std;
- int main()
- {
- //Load Image
- Mat c_src1 = imread( "1.png");
- Mat c_src2 = imread("2.png");
- Mat src1 = imread( "1.png", CV_LOAD_IMAGE_GRAYSCALE);
- Mat src2 = imread( "2.png", CV_LOAD_IMAGE_GRAYSCALE);
- if( !src1.data || !src2.data )
- {
- cout<< "Error reading images " << std::endl;
- return -1;
- }
- //feature detect
- BRISK detector;
- vector<KeyPoint> kp1, kp2;
- double start = GetTickCount();
- detector.detect( src1, kp1 );
- detector.detect( src2, kp2 );
- //cv::BRISK extractor;
- Mat des1,des2;//descriptor
- detector.compute(src1, kp1, des1);
- detector.compute(src2, kp2, des2);
- Mat res1,res2;
- int drawmode = DrawMatchesFlags::DRAW_RICH_KEYPOINTS;
- drawKeypoints(c_src1, kp1, res1, Scalar::all(-1), drawmode);//畫出特征點
- drawKeypoints(c_src2, kp2, res2, Scalar::all(-1), drawmode);
- cout<<"size of description of Img1: "<<kp1.size()<<endl;
- cout<<"size of description of Img2: "<<kp2.size()<<endl;
- BFMatcher matcher(NORM_HAMMING);
- vector<DMatch> matches;
- matcher.match(des1, des2, matches);
- double end = GetTickCount();
- cout<<"耗時:"<<(end - start) <<"ms"<<endl;
- Mat img_match;
- drawMatches(src1, kp1, src2, kp2, matches, img_match);
- cout<<"number of matched points: "<<matches.size()<<endl;
- imshow("matches",img_match);
- cvWaitKey(0);
- cvDestroyAllWindows();
- return 0;
- }
實驗結果

視頻地址
代碼分析
- // construct the image pyramids(構造圖像金字塔)
- void
- BriskScaleSpace::constructPyramid(const cv::Mat& image)
- {
- // set correct size:
- pyramid_.clear();
- // fill the pyramid:
- pyramid_.push_back(BriskLayer(image.clone()));
- if (layers_ > 1)
- {
- pyramid_.push_back(BriskLayer(pyramid_.back(), BriskLayer::CommonParams::TWOTHIRDSAMPLE));//d0層是2/3
- }
- const int octaves2 = layers_;
- for (uchar i = 2; i < octaves2; i += 2)
- {
- pyramid_.push_back(BriskLayer(pyramid_[i - 2], BriskLayer::CommonParams::HALFSAMPLE));//c?層是前兩層的1/2
- pyramid_.push_back(BriskLayer(pyramid_[i - 1], BriskLayer::CommonParams::HALFSAMPLE));//d?層是前兩層的1/2(除d0層外)
- }
- }
- //提取特征點
- void
- BriskScaleSpace::getKeypoints(const int threshold_, std::vector<cv::KeyPoint>& keypoints)
- {
- // make sure keypoints is empty
- keypoints.resize(0);
- keypoints.reserve(2000);
- // assign thresholds
- int safeThreshold_ = (int)(threshold_ * safetyFactor_);
- std::vector<std::vector<cv::KeyPoint> > agastPoints;
- agastPoints.resize(layers_);
- // go through the octaves and intra layers and calculate fast corner scores:
- for (int i = 0; i < layers_; i++)
- {
- // call OAST16_9 without nms
- BriskLayer& l = pyramid_[i];
- l.getAgastPoints(safeThreshold_, agastPoints[i]);
- }
- if (layers_ == 1)
- {
- // just do a simple 2d subpixel refinement...
- const size_t num = agastPoints[0].size();
- for (size_t n = 0; n < num; n++)
- {
- const cv::Point2f& point = agastPoints.at(0)[n].pt;
- // first check if it is a maximum:
- if (!isMax2D(0, (int)point.x, (int)point.y))
- continue;
- // let's do the subpixel and float scale refinement:
- BriskLayer& l = pyramid_[0];
- int s_0_0 = l.getAgastScore(point.x - 1, point.y - 1, 1);
- int s_1_0 = l.getAgastScore(point.x, point.y - 1, 1);
- int s_2_0 = l.getAgastScore(point.x + 1, point.y - 1, 1);
- int s_2_1 = l.getAgastScore(point.x + 1, point.y, 1);
- int s_1_1 = l.getAgastScore(point.x, point.y, 1);
- int s_0_1 = l.getAgastScore(point.x - 1, point.y, 1);
- int s_0_2 = l.getAgastScore(point.x - 1, point.y + 1, 1);
- int s_1_2 = l.getAgastScore(point.x, point.y + 1, 1);
- int s_2_2 = l.getAgastScore(point.x + 1, point.y + 1, 1);
- float delta_x, delta_y;
- float max = subpixel2D(s_0_0, s_0_1, s_0_2, s_1_0, s_1_1, s_1_2, s_2_0, s_2_1, s_2_2, delta_x, delta_y);
- // store:
- keypoints.push_back(cv::KeyPoint(float(point.x) + delta_x, float(point.y) + delta_y, basicSize_, -1, max, 0));
- }
- return;
- }
- float x, y, scale, score;
- for (int i = 0; i < layers_; i++)
- {
- BriskLayer& l = pyramid_[i];
- const size_t num = agastPoints[i].size();
- if (i == layers_ - 1)
- {
- for (size_t n = 0; n < num; n++)
- {
- const cv::Point2f& point = agastPoints.at(i)[n].pt;
- // consider only 2D maxima...
- if (!isMax2D(i, (int)point.x, (int)point.y))
- continue;
- bool ismax;
- float dx, dy;
- getScoreMaxBelow(i, (int)point.x, (int)point.y, l.getAgastScore(point.x, point.y, safeThreshold_), ismax, dx, dy);
- if (!ismax)
- continue;
- // get the patch on this layer:
- int s_0_0 = l.getAgastScore(point.x - 1, point.y - 1, 1);
- int s_1_0 = l.getAgastScore(point.x, point.y - 1, 1);
- int s_2_0 = l.getAgastScore(point.x + 1, point.y - 1, 1);
- int s_2_1 = l.getAgastScore(point.x + 1, point.y, 1);
- int s_1_1 = l.getAgastScore(point.x, point.y, 1);
- int s_0_1 = l.getAgastScore(point.x - 1, point.y, 1);
- int s_0_2 = l.getAgastScore(point.x - 1, point.y + 1, 1);
- int s_1_2 = l.getAgastScore(point.x, point.y + 1, 1);
- int s_2_2 = l.getAgastScore(point.x + 1, point.y + 1, 1);
- float delta_x, delta_y;
- float max = subpixel2D(s_0_0, s_0_1, s_0_2, s_1_0, s_1_1, s_1_2, s_2_0, s_2_1, s_2_2, delta_x, delta_y);
- // store:
- keypoints.push_back(
- cv::KeyPoint((float(point.x) + delta_x) * l.scale() + l.offset(),
- (float(point.y) + delta_y) * l.scale() + l.offset(), basicSize_ * l.scale(), -1, max, i));
- }
- }
- else
- {
- // not the last layer:
- for (size_t n = 0; n < num; n++)
- {
- const cv::Point2f& point = agastPoints.at(i)[n].pt;
- // first check if it is a maximum:
- if (!isMax2D(i, (int)point.x, (int)point.y))
- continue;
- // let's do the subpixel and float scale refinement:
- bool ismax=false;
- score = refine3D(i, (int)point.x, (int)point.y, x, y, scale, ismax);
- if (!ismax)
- {
- continue;
- }
- // finally store the detected keypoint:
- if (score > float(threshold_))
- {
- keypoints.push_back(cv::KeyPoint(x, y, basicSize_ * scale, -1, score, i));
- }
- }
- }
- }
- }
參考文獻
1、BRISK:binary robust invariant scalable keypoints,2011,ICCV.
2、多種角度比較SIFT、SURF、RISK、ORB、FREAK算法[J],2014.
3、基於顏色不變量的特征匹配算法研究[碩士論文],2014.