我是Matlab的初学者。我试图运行这个项目的Matlab代码"图像马赛克使用加速的鲁棒特征检测"这些都是出现的错误。
clear workspace
clear;
clc;
close all;
%//read Reference image and convert into single
rgb1= im2single(imread('r1.jpg'));
I1 = rgb2gray(rgb1);
%//create mosaic background
sz= size(I1)+300;% Size of the mosaic
h=sz(1);
w=sz(2);
%//create a world coordinate system
outputView = imref2d([h,w]);
%//affine matrix
xtform = eye(3);
%// Warp the current image onto the mosaic image
%//using 2D affine geometric transformation
mosaic = imwarp(rgb1, affine2d(xtform),'OutputView', outputView);
figure,imshow(mosaic,'initialmagnification','fit');
%//read Target image and convert into single
rgb2= im2single(imread('t1.jpg'));
I2 = rgb2gray(rgb2);
%//find surf features of reference and target image ,then find new
%//affine matrix
%//Detect SURFFeatures in the reference image
points = detectSURFFeatures(I1);
%//detectSURFFeatures returns information about SURF features detected
%//in the 2-D grayscale input image . The detectSURFFeatures function
%//implements the Speeded-Up Robust Features (SURF) algorithm
%//to find blob features
%//Extract feature vectors, also known as descriptors, and their
%//corresponding locations
[featuresPrev, pointsPrev] = extractFeatures(I1,points);
%//Detect SURFFeatures in the target image
points = detectSURFFeatures(I2);
%//Extract feature vectors and their corresponding locations
[features, points] = extractFeatures(I2,points);
%// Match features computed from the refernce and the target images
indexPairs = matchFeatures(features, featuresPrev);
%// Find corresponding locations in the refernce and the target images
matchedPoints = points(indexPairs(:, 1), :);
matchedPointsPrev = pointsPrev(indexPairs(:, 2), :);
%//compute a geometric transformation from the corresponding locations
tform=estimateGeometricTransform(matchedPoints,matchedPointsPrev,'affine');
%//get affine matrix
xtform = tform.T;
%// Warp the current image onto the mosaic image
mosaicnew = imwarp(rgb2, affine2d(xtform), 'OutputView', outputView);
figure,imshow(mosaicnew,'initialmagnification','fit');
%//create a object to overlay one image over another
halphablender = vision.AlphaBlender('Operation', 'Binary mask', 'MaskSource', 'Input port');
%// Creat a mask which specifies the region of the target image.
%// BY Applying geometric transformation to image
mask= imwarp(ones(size(I2)), affine2d(xtform), 'OutputView', outputView)>=1;
figure,imshow(mask,'initialmagnification','fit');
%//overlays one image over another
mosaicfinal = step(halphablender, mosaic,mosaicnew, mask);
%// %show results
figure,imshow(rgb1,'initialmagnification','fit');
figure,imshow(rgb2,'initialmagnification','fit');
figure,imshow(mosaicfinal,'initialmagnification','fit');
错误:
"Undefined function 'imref2d' for input arguments of type 'double'.
Error in immosaic (line 13)
outputView = imref2d([h,w]);
请帮我正确的代码。
答案 0 :(得分:4)
如果您搜索imref2d
,请在Matlab网站上找到documentation。这是一个非常强烈的迹象,表明您没有图像处理工具箱可用。您应该使用ver
。
一般来说,正如@Sheldon所指出的,这通常意味着Matlab无法找到该函数。在这种情况下,如果您拥有该函数,因为它是在您下载的某个软件包中提供的,请将其复制到您需要的位置,或者使用addpath('path/to/function')
告诉Matlab在哪里找到该函数。
答案 1 :(得分:4)
空间参考对象imref2d是在图像处理工具箱的R2013a版本中引入的。我认为这是Matlab升级的时候!!
答案 2 :(得分:1)
此错误告诉您imref2d函数不存在。
我假设您从其他地方获得了此项目的代码并且缺少文件。确保正确复制了所有代码和文件。