getframe.m
1.41 KB
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
inputheader = '..\data\MICCAI_BraTS_2019_Data_Training\HGG_seg_flair\';
outfolder = '..\data\MICCAI_BraTS_2019_Data_Training\total_frame\';
files = dir(inputheader);
id = {files.name};
% files + dir file
flag = ~strcmp(id, '.') & ~strcmp(id, '..');
files = files(flag);
for i = 1 : length(files)
id = split(files(i).name, '.nii');
id = char(id(1));
fprintf('ID #%d = %s\n', i, id);
filename = id; % BraTS19_2013_2_1_seg_flair.nii
data_path = strcat(inputheader,'\', filename);
data = niftiread(data_path); %size 240x240x155
[x,y,z] = size(data);
for i = 1 : z
[row, col] = find(data(:,:,i) ~= 0);
if(size(row) > 0)
st = i;
break;
end
end
for i = z : -1 : 1
[row, col] = find(data(:,:,i) ~= 0);
if(size(row) > 0)
en = i;
break;
end
end
c = 0;
step = round(((en) - (st))/11);
for k = st + step : step : st + step*10
type = '.png';
filename = strcat(id, '_', int2str(c), type); % BraTS19_2013_2_1_seg_flair_c.png
outpath = strcat(outfolder, filename);
% typecase int16 to double, range[0, 1], rotate 90 and filp updown
cp_data = flipud(rot90(mat2gray(double(data(:,:,k)))));
imwrite(cp_data, outpath);
c = c+ 1;
end
end
% p = 'st: %d\n';
% fprintf(p, st);
% p = 'en: %d\n';
% fprintf(p, en);