- parseInputs what is that?
- full error message please. Line 29 doesn't refer to the function in the question?
parseInputs(varargin{:}) related questions
8 次查看(过去 30 天)
显示 更早的评论
I am trying to calculate the deformation displacement of two MRI images. My code has been shown below:
function [u, cc] = DVC(varargin)
% Parse inputs and create meshgrid
[I,m,mSize,sSize,MTF,M,ccThreshold] = parseInputs(varargin{:});
% Initialize variables
mSize_ = prod(mSize);
u123 = zeros(mSize_,3);
cc = zeros(mSize_,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wb = findall(0,'Tag','TMWWaitbar'); wb = wb(1);
waitbar(1/7,wb,'Estimating Displacements (Time Remaining: )');
for k = 1:mSize_
tStart = tic; % begin timer
%--------------------------------------------------------------------------
% grab the moving subset from the images
A = I{1}(m{1}(k,:),m{2}(k,:),m{3}(k,:));
B = I{2}(m{1}(k,:),m{2}(k,:),m{3}(k,:));
% multiply by the modular transfer function to alter frequency content
A = MTF.*A; B = MTF.*B;
% run cross-correlation
A = xCorr3(A,B,sSize);
% find maximum index of the cross-correlaiton
[cc(k), maxIdx] = max(A(:));
% compute voxel resolution displacements
[u1, u2, u3] = ind2sub(sSize,maxIdx);
% gather the 3x3x3 voxel neighborhood around the peak
try xCorrPeak = reshape(A(u1 + (-1:1), u2 + (-1:1), u3 + (-1:1)),27,1);
% last squares fitting of the peak to calculate sub-voxel displacements
du123 = lsqPolyFit3(xCorrPeak, M{1}, M{2});
u123(k,:) = [u1 u2 u3] + du123' - sSize/2 - 1;
%--------------------------------------------------------------------------
catch
u123(k,:) = nan;
end
% xCorrPeak = reshape(A(u1 + (-1:1), u2 + (-1:1), u3 + (-1:1)),27,1);
%
% % least squares fitting of the peak to calculate sub-voxel displacements
% du123 = lsqPolyFit3(xCorrPeak, M{1}, M{2});
% u123(k,:) = [u1 u2 u3] + du123' - (sSize/2) - 1;
%--------------------------------------------------------------------------
% waitbar calculations (update only every 100 iterations)
if rem(k,100) == 0
tRemaining = (toc(tStart)*(mSize_ - k)); % Time remaining for waitbar
waitbar(1/7*(k/mSize_ + 1),wb,['Estimating Displacements (Time Remaining: ', datestr(datenum(0,0,0,0,0,tRemaining),'MM:SS'),')'])
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reshape displacements and set bad correlations to zero
waitbar(2/7,wb,'Removing Bad Correlations')
%
cc = reshape(double(cc),mSize);
% cc = permute(cc,[2 1 3]);
[cc, ccMask] = removeBadCorrelations(I,cc,ccThreshold);
%
% u = cell(1,3);
% for i = 1:3
% u{i} = reshape(double(u123(:,i)),mSize).*ccMask;
% u{i} = permute(u{i},[2 1 3]);
% end
u{1} = reshape(double(u123(:,2)),mSize).*ccMask;
u{2} = reshape(double(u123(:,1)),mSize).*ccMask;
u{3} = reshape(double(u123(:,3)),mSize).*ccMask;
end
It gets error like
Error in DVC (line 29)
[I,mSize,sSize,ccThreshold] = parseInputs(varargin{:});
5 个评论
Adam
2017-11-21
Well, if it is a toolbox then I assume the function is defined in the toolbox, or probably further down that particular file.
回答(2 个)
Fangjun Jiang
2017-11-21
Regarding parse inputs, you can type "doc parse" in MATLAB and see an example. It is a better way to write a function to have some checks on the input arguments.
If you are new to MATLAB, just ignore this part and provide all the necessary and needed inputs.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!