-1

我正在尝试应用 SURF 算法,该算法是找到关键点并匹配相应的两个图像的算法,但问题是在我的情况下,我想将该算法应用于两个图像,但它们的尺寸不同,所以它无法正常工作,请您告诉我该怎么做才能使两个图像的尺寸相等。

4

2 回答 2

2

这取决于你的问题。如果图像具有相同的分辨率,我建议您裁剪一张图像或扩展一张图像(用零?)以匹配像素数。

否则,我建议您对图像进行插值,以便在相同的点定义它们,例如使用interp2

你能给出一个你正在尝试做的最小工作代码示例吗?

编辑:

您提供的代码示例从加载到图像开始。

% Example 2, Corresponding points
% Load images
I1=imread('TestImages/lena1.png');
I2=imread('TestImages/testc2.png');

以下是一些如何使图像匹配的示例。您必须决定其中哪一个对您的情况有意义。

方法一:裁剪两张图片

nrows = min(size(I1,1), size(I2,1));
ncols = min(size(I1,2), size(I2,2));

% The + floor( ... ) is only for centering the bounding box
croppedI1 = I1( (1:nrows) + floor((size(I1,1)-nrows)/2), ...
  (1:ncols)+floor((size(I1,2)-ncols)/2), ...
  :);

croppedI2 = I2( (1:nrows) + floor((size(I2,1)-nrows)/2, ...
  (1:ncols) + floor((size(I2,2)-ncols)/2), ...
  :);

I1=croppedI1;
I2=croppedI2;

方法2:用零扩展图像直到它们匹配

nrows = max(size(I1,1), size(I2,1));
ncols = max(size(I1,2), size(I2,2));
nchannels = size(I1,3);

extendedI1 = [ I1, zeros(size(I1,1), ncols-size(I1,2), nchannels); ...
  zeros(nrows-size(I1,1), ncols, nchannels)];

extendedI2 = [ I2, zeros(size(I2,1), ncols-size(I2,2), nchannels); ...
  zeros(nrows-size(I2,1), ncols, nchannels)];

I1=extendedI1;
I2=extendedI2;

方法3:将第二张图片缩放到第一张的大小(这会破坏纵横比)

% Scale the coordinates so that they range from 0 to 1 each.
[X1, Y1]=meshgrid( linspace(0, 1, size(I1,2)), linspace(0, 1, size(I1,1)));
[X2, Y2]=meshgrid( linspace(0, 1, size(I2,2)), linspace(0, 1, size(I2,1)));
nchannels = size(I1,3);

% interpolate each color plane separately
for k=1:nchannels
  scaledI2(:,:,k)=interp2(X2, Y2, double(I2(:,:,k)), X1, Y1); 
end

%I1=I1;
I2=scaledI2;
于 2012-04-16T04:57:50.123 回答
0
% code for to play the images or to take same size images into array

r=0;c=0;

a1=imread(filename1);    

[r c]=size(a1);

b=imread(filename2);

a2= imresize(b, [r c/3]); 

% re-sized second image according to 1st one if u have specific   
 row col number then you can give like that 

a=cat(4,a1,a2);       % "a" array having a1 a2 images       

implay(a,framerate );   % to play images
于 2013-07-04T17:21:42.020 回答