-
Notifications
You must be signed in to change notification settings - Fork 2
/
e03_2_stripData.m
78 lines (69 loc) · 2.51 KB
/
e03_2_stripData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
% Pre-processing of QIN Breast DCE-MRI data.
% This script will strip away all non-tumour slices and build a tumour mask.
% This is done to save time. The original data covers the entire breast,
% but we are only interested in the slices containing the tumour.
% This step was done because during the research work, the data was processed
% multiple times for various reasons. Loading the data was the slowest part
% of the procedure, so the non-tumour slices were stripped away in order to
% decrease wait times and keep RAM usage low.
% After running the script, the './data/QINBreast' folder is no longer needed
% and can be deleted to free up 8 Gb of space
% Run time: ~415 seconds
%% General setup
clearvars
addpath('./mfiles')
doOverwrite = 0; % Overwrite any existing output
%% Initialize
dirLocation = DefaultFolders();
matDir = fullfile(dirLocation.qin,'Unzipped');
outDir = fullfile(dirLocation.qin,'Stripped');
% Make output directory if it doesn't exist
if ~exist(outDir,'dir')
mkdir(outDir)
end
%% Do the job
tic
% Get list of .mat files
matFiles = dir([matDir '/*.mat']);
%Cycle through .mat files
for q=1:length(matFiles)
% Clear variables to keep memory usage low
clearvars -except matDir matFiles outDir q doOverwrite
% Load data
curName = matFiles(q).name;
curFile = fullfile(matDir,curName);
outFile = fullfile(outDir,curName);
if ~doOverwrite && exist(outFile,'file')
% Skip file if output already exists
continue;
end
disp(['Processing ' curName]);
load(curFile);
% Grab the information struct, and add info about rows/column/slices
dataInfo = da.para;
dataInfo.nX = da.hdr.Rows;
dataInfo.nY = da.hdr.Columns;
dataInfo.nZ = numel(da.slcList);
% Grab the data from only the tumour-containing slices & grab AIF
dynData = da.data(:,:,da.slcList,:);
aif=da.aif;
% Build the mask for the tumour region
mask = zeros(dataInfo.nX, dataInfo.nY, dataInfo.nZ);
for r=1:numel(da.slcList)
curSlice = da.slcList(r);
curMask = zeros(320*320,1);
curMask(da.slcdata(curSlice).Q)=1;
mask(:,:,r)=reshape(curMask,[dataInfo.nX dataInfo.nY]);
end
% Patient BC05 seems to have extra precontrast frame? Remove it
if ~isempty(findstr(curName,'BC05'))
dynData(:,:,:,1)=[];
dataInfo.BaseLineEnd = dataInfo.BaseLineEnd-1;
end
% Save to output directory, using the same filename as the input file
save(outFile, 'dynData', 'mask', 'aif', 'dataInfo');
end
toc
disp('...')
disp('...')
disp('done')