D-SIFT

dense sift即直接指定关键点位置和描述子采样区域,计算sift特征。一些介绍:http://www.vlfeat.org/api/dsift.html
主要过程是:
1,用一个patch在图像上以一定步长step滑动,代码中step=1,这个patch就是描述子采样区域,patch size是4bins*4bins,bin size可以自己指定,代码中是3pixels*3pixels。这里说的bin对应到《sift特征提取》中的第4步就是指子区域area。图中的bounding box是sift特征点的范围。
这里写图片描述
2,计算每个像素点的梯度(同sparse sift),统计每个bin内的像素点在8个方向上的梯度直方图,这样就生成了4*4*8维的sift特征。
这里写图片描述

代码来自SPM的包里面:

function [ SIFTFeatureVector, locationX, locationY ] = DenseSIFT( image, nPatchSize, nGridSpacing )

image = double( image );
image = mean( image, 3 );
image = image / max( image( : ) );

% parameters
nAngleNums = 8;
nBinNums = 4;
nSampleNums = nBinNums * nBinNums;
alpha = 9; %% parameter for attenuation of angles (must be odd)

if nargin < 5
    sigmaGuassian = 1;
end

angleStep = 2 * pi / nAngleNums;
angles = 0 : angleStep : 2 * pi;
angles( nAngleNums + 1 ) = [ ]; % bin centers

[ nRow nCol ] = size( image );

[ gaussianX, gaussianY ] = genDeltaGaussian( sigmaGuassian );
imageVerticalEdges = filter2( gaussianX, image, 'same' ); % vertical edges
imageHorizontalEdges = filter2( gaussianY, image, 'same' ); % horizontal edges
imageGradientMagnitude = sqrt( imageVerticalEdges.^2 + imageHorizontalEdges.^2 ); % gradient magnitude
imageTheta = atan2( imageHorizontalEdges, imageVerticalEdges );
imageTheta(  isnan( imageTheta )  ) = 0; % replace illegal result with 0

% descriptor locations
locationX = nPatchSize / 2 : nGridSpacing : nCol - nPatchSize / 2 + 1;
locationY = nPatchSize / 2 : nGridSpacing : nRow - nPatchSize / 2 + 1;

% make orientation images
imageOrientation = zeros( [ nRow, nCol, nAngleNums ], 'single' );

% for each histogram angle
imageCos = cos( imageTheta );
imageSin = sin( imageTheta );

for index = 1 : nAngleNums
    % compute each orientation channel
    tmp = ( imageCos * cos( angles( index ) ) + imageSin * sin( angles( index ) ) ).^ alpha;
    tmp = tmp .* ( tmp > 0 );
    
    % weight by magnitude
    imageOrientation( :, :, index ) = tmp .* imageGradientMagnitude;
end

% Convolution formulation:
nHalfPatchSize = nPatchSize / 2;
nHalfPatchSizeMinusDotFive = nHalfPatchSize - 0.5;
sampleResolution = nPatchSize / nBinNums;
weightX = abs( ( 1 : nPatchSize ) - nHalfPatchSizeMinusDotFive ) / sampleResolution;
weightX = ( 1 - weightX ) .* ( weightX <= 1 );

for index = 1 : nAngleNums
    imageOrientation( :, :, index ) = conv2( weightX, weightX', imageOrientation( :, :, index ), 'same' );
end

% Sample SIFT bins at valid locations (without boundary artifacts)
% find coordinates of sample points (bin centers)
[ samplePosX, samplePosY ] = meshgrid( linspace( 1, nPatchSize + 1, nBinNums + 1 ) );
samplePosX = samplePosX( 1 : nBinNums, 1 : nBinNums ); samplePosX = samplePosX( : ) - nPatchSize / 2;
samplePosY = samplePosY( 1 : nBinNums, 1 : nBinNums ); samplePosY = samplePosY( : ) - nPatchSize / 2;

SIFTFeatureVector = zeros( [ length( locationY ) length( locationX ) nAngleNums * nSampleNums ] , 'single' );

nOffset = 0;
for n = 1 : nBinNums * nBinNums
    SIFTFeatureVector( :, :, nOffset + 1 : nOffset + nAngleNums ) = imageOrientation( locationY + samplePosY(n), locationX + samplePosX(n), : );
    nOffset = nOffset + nAngleNums;
end

clear imageOrientation


% Outputs:
[ locationX, locationY ] = meshgrid( locationX, locationY );
[ nrows, ncols, cols ] = size( SIFTFeatureVector );

% normalize SIFT descriptors
SIFTFeatureVector = reshape( SIFTFeatureVector, [nrows * ncols nAngleNums * nSampleNums ] );
SIFTFeatureVector = SIFTNormalization( SIFTFeatureVector );
SIFTFeatureVector = reshape( SIFTFeatureVector, [ nrows ncols nAngleNums * nSampleNums]  );


function [ GX, GY ] = genDeltaGaussian( sigma )

% laplacian of size sigma

G = genGaussian(sigma);
[ GX, GY ] = gradient( G );

GX = GX * 2 ./ sum( sum( abs( GX ) ) );
GY = GY * 2 ./ sum( sum( abs( GY ) ) );

function G = genGaussian( sigma )

if all( size( sigma ) == [ 1, 1 ] )
    % isotropic gaussian
    filterWindow = 4 * ceil( sigma ) + 1;
    G = fspecial( 'gaussian', filterWindow, sigma );
else
    % anisotropic gaussian
    filterWindowX = 2 * ceil( sigma( 1 ) ) + 1;
    filterWindowY = 2 * ceil( sigma( 2 ) ) + 1;
    GaussianX = normpdf( -filterWindowX: filterWindowX, 0, sigma( 1 ) );
    GaussianY = normpdf( -filterWindowY: filterWindowY, 0, sigma( 2 ) );
    G = GaussianY' * GaussianX;
end

function SIFTFeatureVector = SIFTNormalization( SIFTFeatureVector )
% normalize SIFT descriptors (after Lowe)

% find indices of descriptors to be normalized (those whose norm is larger than 1)
tmp = sqrt( sum( SIFTFeatureVector.^2, 2 ) );
normalizeIndex = find( tmp > 1 );

SiftFeatureVectorNormed = SIFTFeatureVector( normalizeIndex, : );
SiftFeatureVectorNormed = SiftFeatureVectorNormed ./ repmat( tmp( normalizeIndex, : ), [ 1 size( SIFTFeatureVector, 2 ) ] );

% suppress large gradients
SiftFeatureVectorNormed( SiftFeatureVectorNormed > 0.2 ) = 0.2;

% finally, renormalize to unit length
tmp = sqrt( sum( SiftFeatureVectorNormed.^2, 2 ) );
SiftFeatureVectorNormed = SiftFeatureVectorNormed ./ repmat( tmp, [ 1 size( SIFTFeatureVector, 2 ) ] );

SIFTFeatureVector( normalizeIndex, : ) = SiftFeatureVectorNormed;



  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SIFT(Scale-invariant feature transform)是一种用于关键点检测的算法,最初由加拿大University of British Columbia大学计算机科学系教授David G. Lowe在2004年的论文中提出\[1\]。SIFT算法具有对均匀缩放、方向、亮度变化和对仿射失真不变的特点。在SIFT算法的Matlab实现中,可以使用作者在其学术网站上提供的代码\[1\]。这个代码最初版本是由D. Alvaro和J.J. Guerrero来自Universidad de Zaragoza提供的。 除了SIFT算法,还有其他一些受SIFT启发的算法,如SURF(Speeded Up Robust Features)、ORB(Oriented FAST and Rotated BRIEF)和AKAZE(Accelerated-KAZE)。这些算法都具有不同的特点和优势,并且可以在OpenCV中轻松使用\[2\]。 在Matlab中,可以使用sift.m函数来实现SIFT算法的核心功能。该函数接受灰度图像作为输入,并返回SIFT特征关键点、描述子和位置信息。其中,描述子是一个128维的向量,用于表示每个关键点的特征\[3\]。 总结起来,如果你想在Matlab中实现SIFT算法,你可以使用David G. Lowe在其学术网站上提供的代码,并调用sift.m函数来提取SIFT特征关键点和描述子。这样可以帮助你在图像处理和计算机视觉任务中进行特征提取和匹配。 #### 引用[.reference_title] - *1* *3* [Matlab实现sift特征检测和两幅图像的特征点匹配(D. Lowe)](https://blog.csdn.net/qq_45717425/article/details/120918117)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [SIFT特征提取和图像配准MATLAB仿真](https://blog.csdn.net/ccsss22/article/details/130172335)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值