조현아

get frames & nii2png

1 +inputheader = '..\data\MICCAI_BraTS_2019_Data_Training\HGG_seg_flair\';
2 +outfolder = '..\data\MICCAI_BraTS_2019_Data_Training\frame\';
3 +
4 +files = dir(inputheader);
5 +id = {files.name};
6 +% files + dir file
7 +flag = ~strcmp(id, '.') & ~strcmp(id, '..');
8 +files = files(flag);
9 +
10 +
11 +for i = 1 : length(files)
12 +
13 + id = split(files(i).name, '.nii');
14 + id = char(id(1));
15 + fprintf('ID #%d = %s\n', i, id);
16 + filename = id; % BraTS19_2013_2_1_seg_flair.nii
17 + data_path = strcat(inputheader,'\', filename);
18 + data = niftiread(data_path); %size 240x240x155
19 +
20 + [x,y,z] = size(data);
21 +
22 + for i = 1 : z
23 + [row, col] = find(data(:,:,i) ~= 0);
24 + if(size(row) > 0)
25 + st = i;
26 + break;
27 + end
28 + end
29 +
30 + for i = z : -1 : 1
31 + [row, col] = find(data(:,:,i) ~= 0);
32 + if(size(row) > 0)
33 + en = i;
34 + break;
35 + end
36 + end
37 +
38 + c = 0;
39 + step = round(((en) - (st))/11);
40 + for k = st + step : step : st + step*10
41 + c = c+ 1;
42 +
43 + type = '.png';
44 + filename = strcat(id, '_', int2str(c), type); % BraTS19_2013_2_1_seg_flair_c.png
45 + outpath = strcat(outfolder, filename);
46 + % typecase int16 to double, range[0, 1], rotate 90 and filp updown
47 + cp_data = flipud(rot90(mat2gray(double(data(:,:,k)))));
48 + imwrite(cp_data, outpath);
49 + end
50 +
51 +end
52 +
53 +
54 +% p = 'st: %d\n';
55 +% fprintf(p, st);
56 +% p = 'en: %d\n';
57 +% fprintf(p, en);
58 +