sift源码解析

本文介绍了SIFT特征提取算法的源码解析,包括图像预处理、梯度计算、角度和强度分配,以及如何在网格中寻找SIFT特征。代码中未进行尺度空间变换和极值检测,直接在每个patch内提取128维特征。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

function [] = GenerateSiftDescriptors(opts,descriptor_opts)
%function [] = GenerateSiftDescriptors( opts,descriptor_opts )
%
%Generate the dense grid of sift descriptors for each
%
fprintf('Building Sift Descriptors\n\n');

%% parameters
descriptor_flag=1;
maxImageSize = descriptor_opts.maxImageSize;
gridSpacing = descriptor_opts.gridSpacing;
patchSize = descriptor_opts.patchSize;

try
    descriptor_opts2=getfield(load([opts.globaldatapath,'/',descriptor_opts.name,'_settings']),'descriptor_opts');
    if(isequal(descriptor_opts,descriptor_opts2))
        descriptor_flag=0;
        display('descriptor has already been computed for this settings');
    else
        display('Overwriting descriptor with same name, but other descriptor settings !!!!!!!!!!');
    end
end


if(descriptor_flag)
    
    %% load image
    imgpath=strcat(opts.imgpath,'/*.jpg');
    fileNames = dir(imgpath); % load image in data set
    nimages=length(fileNames);           % number of images in data set
    
    h = waitbar(0,'compute SIFT...');
    for f = 1:nimages
        %此处开始对单幅图像的sift特征进行提取 
        imgpath=[opts.imgpath,'/',fileNames(f).name];%图像存储地址
        I=load_image(imgpath);%载入图像,load_image对图像进行预处理,若图像为彩色图像,则将其转化为灰度图,具体代码附后
        
        tic
        
        [hgt wid] = size(I);%计算图像矩阵的高度和宽度
        
	%对图像大小进行处理
	if min(hgt,wid) > maxImageSize
            I = imresize(I, maxImageSize/min(hgt,wid), 'bicubic');%采用<a target=_blank href="http://baike.baidu.com/view/699995.htm" target="_blank">双三次插值</a>算法将图像所方位原图像的maxImageSize/min(hgt,wid)倍
            fprintf('Loaded %s: original size %d x %d, resizing to %d x %d\n', ...
                fileNames(f).name, wid, hgt, size(I,2), size(I,1));
            [hgt wid] = size(I);%重新计算图像矩阵的高度和宽度
        end
        
        %至此,图像的高度和宽度分别储存在hgt,wid中
        %% make grid (coordinates of upper left patch corners)
        remX = m
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值