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_dartel_resids.m
    path of file: ./repos/spm/toolbox/DARTEL
    
    the code of the file until where you have to start completion: function out = spm_dartel_resids(job)
% Generate residuals in a form suitable for generating a Fisher kernel
% FORMAT spm_dartel_residuals(job)
% job.flowfields
% job.images
% job.template
% job.K
%
% The aim is to obtain better pattern recognition through using
% Fisher kernels.  See  Bishop's PRML or the work of Jaakkola and
% Haussler for more information.
%__________________________________________________________________________


    
function out = spm_dartel_resids(job)
% Generate residuals in a form suitable for generating a Fisher kernel
% FORMAT spm_dartel_residuals(job)
% job.flowfields
% job.images
% job.template
% job.K
%
% The aim is to obtain better pattern recognition through using
% Fisher kernels.  See  Bishop's PRML or the work of Jaakkola and
% Haussler for more information.
%__________________________________________________________________________

% John Ashburner
% Copyright (C) 2006-2022 Wellcome Centre for Human Neuroimaging


PG = job.template{1};
PI = job.images;
PU = job.flowfields;
K  = job.K;
fwhm = job.fwhm;

N  = nifti(PG);
dm = size(N.dat);
n  = dm(4);


spm_progress_bar('Init',dm(3),'Generating Covariances','Planes complete');
% Load mean values from template
mu = zeros([dm(1:3),n+1],'single');
mu(:,:,:,end