parseInputs(varargin{:}) related questions
Show older comments
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 Comments
per isakson
on 20 Nov 2017
- parseInputs what is that?
- full error message please. Line 29 doesn't refer to the function in the question?
tao wang
on 21 Nov 2017
Instruction from where? Coding would certainly be a lot easier if all we needed to do was just make a call to a function with the name given in a written instruction and the function would magically create itself and know exactly what we want it to do! But parseInputs is not part of base Matlab or any toolbox I have and you haven't shown us any implementation of it so based on the information you give this function simply doesn't exist.
tao wang
on 21 Nov 2017
Edited: per isakson
on 21 Nov 2017
Adam
on 21 Nov 2017
Well, if it is a toolbox then I assume the function is defined in the toolbox, or probably further down that particular file.
Answers (2)
BA
on 10 Feb 2018
it could be a hidden function which can be accessed via
which -all parseInputs
Fangjun Jiang
on 21 Nov 2017
0 votes
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.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!