% Folder paths that you can change for your directory.
prefix_T1 = './DICOM Psych/akihlMarch10/DICOM Export Folder/akhil/unnamed/TOF - MT/';
ss_T1 = 'IM-0002-0';%The prefix of each dcm file
data = zeros(256,256,66,4);%All exams are going to be stored in
                           %this format
num_exam = 4; %Number of seperate exams
num_slice = 66; %Number of slices

for exam=1:num_exam;%For each flip angle for T1
   for slice=1:num_slice; 
    ind =(exam-1)*num_slice+slice; %Find the DCM number
    if (ind<10) %Create the filename
         filename = sprintf('%s%s%d%d%d%s',prefix_T1,ss_T1,0,0,ind,'.dcm');
    else if (ind<100)
         filename = sprintf('%s%s%d%d%s',prefix_T1,ss_T1,0,ind,'.dcm');
    else 
      filename = sprintf('%s%s%d%s',prefix_T1,ss_T1,ind,'.dcm');
    end
    info = dicominfo(filename);%Read the DICOM slice
    data(:,:,slice,exam) = dicomread(info);
   end
end
end

%Just cut-off the unnecessary parts of the image
data = data(129-63:129+64,129-63:129+64,:,:);

%For each exam we need zero padding in the slice direction
%Scanner takes care of the other two directions for DICOM images.
for exam = 1:4;
ims =data(:,:,:,exam);
s = size(ims);
ims = fftshift(fftn(fftshift(ims)));

FOV(3) = 2.8*66;
ind(3) = ceil(FOV(3)/1.4);
ims(:,:,ind(3)) = 0; 
ims=ifftshift(ims);
ims=ifftn(ims);
ims=ifftshift(ims);
MTdata(:,:,:,exam) = ims;
end

%I have done this only for T1 but MT is just changing the prefixes
%at the beginning.
save akhil_T1data T1data;
