flair2seg_all.m 1.3 KB
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