云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > sift算法的MATLAB程序

sift算法的MATLAB程序

  • 62 次阅读
  • 3 次下载
  • 2025/5/25 16:02:19

% [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 \ 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.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算法的MATLAB程序 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

% [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.

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com