我是一個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]);
請幫助我正確的代碼。
雖然完全沒有線索的matlab,錯誤sggests你提供錯誤的參數,以函數imref2d([h,w]);.它似乎需要一個高度和寬度,可能是整數,但你提供了一個雙倍大小的數字。看看那個。你可能需要在這裏舍入這個結果:sz = size(I1)+300;%馬賽克的大小 – 2014-08-29 06:34:25
2問題:(1)在第13行放置一個斷點,運行你的代碼到那一點,打印出值命令行中的'h'和'w',並在這裏回報。 (2)您是否安裝了圖像處理工具箱?在命令行鍵入'ver'來檢查 – Dan 2014-08-29 06:36:46
@KaiMattern,在Matlab中這個錯誤信息實際上表明該函數根本就沒有。這很少意味着你提出了錯誤的觀點,而且在這裏,關於double/ints應該沒有問題。 – Unapiedra 2014-08-29 06:47:15