2014-08-29 162 views
-2

我是一個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

雖然完全沒有線索的matlab,錯誤sggests你提供錯誤的參數,以函數imref2d([h,w]);.它似乎需要一個高度和寬度,可能是整數,但你提供了一個雙倍大小的數字。看看那個。你可能需要在這裏舍入這個結果:sz = size(I1)+300;%馬賽克的大小 – 2014-08-29 06:34:25

+1

2問題:(1)在第13行放置一個斷點,運行你的代碼到那一點,打印出值命令行中的'h'和'w',並在這裏回報。 (2)您是否安裝了圖像處理工具箱?在命令行鍵入'ver'來檢查 – Dan 2014-08-29 06:36:46

+1

@KaiMattern,在Matlab中這個錯誤信息實際上表明該函數根本就沒有。這很少意味着你提出了錯誤的觀點,而且在這裏,關於double/ints應該沒有問題。 – Unapiedra 2014-08-29 06:47:15

回答

1

這個錯誤告訴你函數imref2d不存在。

我假設你從其他地方得到了這個項目的代碼,並且缺少一個文件。確保你正確地複製了所有的代碼和文件。

4

如果您搜索imref2d,您可以在Matlab網站上找到這個documentation。這是一個非常強烈的跡象表明,您沒有可用的圖像處理工具箱。你應該使用ver來檢查。

一般來說,正如@Sheldon指出的,這通常意味着函數不能被Matlab找到。在這種情況下,如果您擁有該功能,因爲它是在您下載的某個軟件包中提供的,請將其複製到您需要的位置,或者,使用addpath('path/to/function')來告訴Matlab哪裏可以找到該功能。

4

空間引用對象imref2d是在Image Processing Toolbox的R2013a版本中引入的。我認爲它是用於Matlab升級的時間!

+0

2012a有沒有可用的功能,而不是imref2d? – 2014-08-29 07:00:39

+0

我不知道確切的,但下面的帖子應該幫助你,我猜! http://stackoverflow.com/questions/15693510/the-replacement-of-worldtointrinsic-function-in-r2012a-or-below – yoyo 2014-08-29 07:06:55