%reset random generator
rng shuffle

%add nrrd processing capability
addpath('nrrd_read_write_rensonnet')
disp('Test');
[cax,cm]=loadTime(path,patientID);

%segmFile=fullfile(path,patientID,sprintf('%s_Segmentation.txt',patientID));
%v0=loadPixels(segm,patientID);
[filepath,name,suffix]=fileparts(segmFile);
if contains(suffix,'nrrd')
    v0=extractPixelsFromNrrd(segmFile);
end
if contains(suffix,'txt')
    v0=dlmread(segmFile);
    n=size(v0,1);
    v0=[(1:n)' v0];
end

data=loadSPECTdata(path,patientID,cm);

sigma2=str2num(sigma2);
na=7;
fcenters=extractCenters(data,v0,sigma2,na);

%this will write out fitPar
[globalPar, cPars] = fitCentersPixelIVF(path, patientID, cax, cm, fcenters,sigma2);

%[globalPar, cPars, xa, U]=fitFromClusters(path,cax, cm, data, nclass,realizationId);

disp('DynamicPixelAnalysis done\n');
quit;
%writeData
