You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: spm_invert_def.m
    path of file: ./repos/malini/Codes/deconvolution - model/spm8/toolbox/Seg
    
    the code of the file until where you have to start completion: function y = spm_invert_def(y,M1,d0,M0,args)
% Invert a deformation field
% FORMAT iY = spm_invert_def(Y,M,idim,iM,args)
% Y    - input deformation field (floating point n1*n2*n3*3)
% M    - voxel-to-world mapping of deformation field
% idim - dimensions of inverse deformation

    
function y = spm_invert_def(y,M1,d0,M0,args)
% Invert a deformation field
% FORMAT iY = spm_invert_def(Y,M,idim,iM,args)
% Y    - input deformation field (floating point n1*n2*n3*3)
% M    - voxel-to-world mapping of deformation field
% idim - dimensions of inverse deformation
% iM   - voxel-to-world mapping of inverse deformation
% args - additional arguments (optional)
%        * If the first element is non-zero, then assume the
%          original mapping is to voxel indices, rather than to
%          mm coordinates.
%        * If the second element is non-zero, then assume the
%          output mapping is to voxel indices.
%
% iY   - inverse deformation field
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% John Ashburner
% $Id: spm_invert_def.m 3211 2009-06-19 12:34:26Z john $


d1 = size(y);
d1 = d1(1:3);
d0 = d0(1:3);

if nargin<5 || numel(args)<1 || ~args(1),
    % y maps from individual to mm coordinates in the template.  Change
    % this so that it maps to voxel indices in the template instead.
    y      = affind(y,inv(M1));
end