SIFT-sift.m
2015-04-16 15:22
435 查看
留坑,回头来写注释
% [image, descriptors, locs] = sift(imageFile) % % This function reads an image and returns its SIFT keypoints. % Input parameters: % imageFile: the file name for the image. % % Returned: % image: the image array in double format % descriptors: a K-by-128 matrix, where each row gives an invariant % descriptor for one of the K keypoints. The descriptor is a vector % of 128 values normalized to unit length. % locs: K-by-4 matrix, in which each row has the 4 values for a % keypoint location (row, column, scale, orientation). The % orientation is in the range [-PI, PI] radians. % % Credits: Thanks for initial version of this program to D. Alvaro and % J.J. Guerrero, Universidad de Zaragoza (modified by D. Lowe) function [image, descriptors, locs] = sift(imageFile) % Load image image = imread(imageFile); % If you have the Image Processing Toolbox, you can uncomment the following % lines to allow input of color images, which will be converted to grayscale. % if isrgb(image) % image = rgb2gray(image); % end [rows, cols] = size(image); % Convert into PGM imagefile, readable by "keypoints" executable f = fopen('tmp.pgm', 'w'); if f == -1 error('Could not create file tmp.pgm.'); end fprintf(f, 'P5\n%d\n%d\n255\n', cols, rows); fwrite(f, image', 'uint8'); fclose(f); % Call keypoints executable if isunix command = '!./sift '; else command = '!siftWin32 '; end command = [command ' <tmp.pgm >tmp.key']; eval(command); % Open tmp.key and check its header g = fopen('tmp.key', 'r'); if g == -1 error('Could not open file tmp.key.'); end [header, count] = fscanf(g, '%d %d', [1 2]); if count ~= 2 error('Invalid keypoint file beginning.'); end num = header(1); len = header(2); if len ~= 128 error('Keypoint descriptor length invalid (should be 128).'); end % Creates the two output matrices (use known size for efficiency) locs = double(zeros(num, 4)); descriptors = double(zeros(num, 128)); % Parse tmp.key for i = 1:num [vector, count] = fscanf(g, '%f %f %f %f', [1 4]); %row col scale ori if count ~= 4 error('Invalid keypoint file format'); end locs(i, :) = vector(1, :); [descrip, count] = fscanf(g, '%d', [1 len]); if (count ~= 128) error('Invalid keypoint file value.'); end % Normalize each input vector to unit length descrip = descrip / sqrt(sum(descrip.^2)); descriptors(i, :) = descrip(1, :); end fclose(g);
相关文章推荐
- 三种强大的物体识别算法——SIFT/SURF、haar特征、广义hough变换的特性对比分析
- SIFT keypoint detect
- [转] 三种强大的物体识别算法——SIFT/SURF、haar特征、广义hough变换的特性对比分析
- 从vc6.0转到vs中出现的错误解析!(有感于sift和surf移植)
- SIFT算法不完全手册(第二季)_相关概念(转)
- 用SIFT识别物体
- SIFT特征匹配中的相关问题
- sift是图像匹配的非常经典的算法
- SIFT特征介绍以及程序下载
- SIFT学习--特征点获取
- SIFT-----Local 特征的经典之作
- 基于vs2008的OpenCV2.3.1配置及SIFT算法实现
- 应用Sift算子的模式识别方法 内核篇
- SIFT特征提取分析(特征点篇)
- 谈谈SIFT、PCA-SIFT、SURF及我的一点思考
- 图像拼接 SIFT资料合集
- sift算法不要用opencv2.4.3来写,因为sift的有关东西都移到nonfree模块了。用2.3.1版本的吧,少年。。
- SIFT中的尺度空間和傳統圖像金字塔
- SIFT特征提取分析(特征点篇)
- SIFT,SURF和PCA-SIFT对比