getNormalFrames.m 1.13 KB
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);