getNormalFrames.m
1.13 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
inputheader = '..\data\Normal_all\';
outfolder = '..\data\Normal_frames\';
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);
c = 0;
for k = 18:24
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
% range [0, 1]
%cp_data = flipud(rot90(mat2gray(double(data(:,:,k)))));
cp_data = flipud(rot90(mat2gray(double(data(:,:,k)))));
% M = max(cp_data(:));
% disp(M);
imwrite(cp_data, outpath);
c = c+ 1;
end
end
% p = 'st: %d\n';
% fprintf(p, st);
% p = 'en: %d\n';
% fprintf(p, en);