flair2seg_all.m
1.3 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
inputheader = '..\data\MICCAI_BraTS_2019_Data_Training\HGG\';
outfolder = strcat('..\data\MICCAI_BraTS_2019_Data_Training\HGG_seg_flair\');
files = dir(inputheader);
id = {files.name};
% 하위 files + dir 중 dir만 선택
dirFlag = [files.isdir] & ~strcmp(id, '.') & ~strcmp(id, '..');
subFolders = files(dirFlag);
disp(length(subFolders));
% for k = 1 : length(subFolders)
% fprintf('Sub folder #%d = %s\n', k, subFolders(k).name);
% end
for i = 1 : length(subFolders)
id = subFolders(i).name;
fprintf('Sub folder #%d = %s\n', i, id);
type = 'flair.nii';
filename = strcat(id,'_', type); % BraTS19_2013_2_1_flair.nii
flair_path = strcat(inputheader, id, '\', filename,'\', filename);
flair = niftiread(flair_path); %size 240x240x155
cp_flair = flair;
type = 'seg.nii';
filename = strcat(id,'_', type); % BraTS19_2013_2_1_seg.nii
seg_path = strcat(inputheader, id, '\', filename, '\', filename);
seg = niftiread(seg_path);
[x,y,z] = size(seg);
% copy flair, segment flair data
% seg의 검은 부분(정보 x)과 같은 인덱스 = 0
cp_flair(seg == 0) = 0;
% save a segmented data
type = 'seg_flair.nii';
filename = strcat(id,'_', type); % BraTS19_2013_2_1_seg_flair.nii
outpath = strcat(outfolder, filename);
niftiwrite(cp_flair, outpath);
end