조현아

mv getframe codes

inputheader = '..\data\MICCAI_BraTS_2019_Data_Training\HGG_seg_flair\';
outfolder = '..\data\MICCAI_BraTS_2019_Data_Training\total_frame\';
outfolder = '..\data\MICCAI_BraTS_2019_Data_Training\total_frame_m255\';
files = dir(inputheader);
id = {files.name};
......@@ -8,7 +8,7 @@ flag = ~strcmp(id, '.') & ~strcmp(id, '..');
files = files(flag);
for i = 1 : length(files)
for i = 1 : 1%length(files)
id = split(files(i).name, '.nii');
id = char(id(1));
......@@ -42,7 +42,11 @@ for i = 1 : length(files)
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
cp_data = flipud(rot90(mat2gray(double(data(:,:,k)))));
% range [0, 1]
%cp_data = flipud(rot90(mat2gray(double(data(:,:,k)))));
cp_data = flipud(rot90(mat2gray(double(data(:,:,k))))).*255;
% M = max(cp_data(:));
% disp(M);
imwrite(cp_data, outpath);
c = c+ 1;
......
data_path = '..\data\MICCAI_BraTS_2019_Data_Training\HGG_seg_flair\BraTS19_CBICA_AVG_1_seg_flair.nii';
data = niftiread(data_path);
cp_data = flipud(rot90(mat2gray(double(data(:,:,82)))));
type = '.png';
filename = strcat('BraTS19_CBICA_AVG_1_seg_flair_8', type); % BraTS19_2013_2_1_seg_flair_c.png
outpath = strcat('..\data\MICCAI_BraTS_2019_Data_Training\zero to valid\', filename);
imwrite(cp_data, outpath);
% st, end 10
%% (circle 0, ellipse 0)
% BraTS19_CBICA_AOP_1_seg_flair_0
% BraTS19_CBICA_ASF_1_seg_flair_9 -> 8
% BraTS19_CBICA_ASR_1_seg_flair_8
% BraTS19_CBICA_ASR_1_seg_flair_9
% BraTS19_CBICA_AVG_1_seg_flair_9 -> 8
%
%
%
%
%
%
%
%
%
%
%
%
\ No newline at end of file
getname_path = '..\data\MICCAI_BraTS_2019_Data_Training\zero2\';
inputheader = '..\data\MICCAI_BraTS_2019_Data_Training\HGG_seg_flair\';
outfolder = '..\data\MICCAI_BraTS_2019_Data_Training\zero to valid2\';
files = dir(getname_path);
id = {files.name};
% files + dir file
flag = ~strcmp(id, '.') & ~strcmp(id, '..');
files = files(flag);
% get filenames in getname_path folder
for i = 1 : length(files)
%id = split(files(i).name, '.nii');
fname = files(i).name;
id = reverse(extractBetween(reverse(fname), 7, strlength(fname)));
data_path = convertCharsToStrings(strcat(inputheader,'\', id, '.nii'));
data = niftiread(data_path);
fprintf('ID #%d = %s\n', i, data_path);
idx = 1;
frames = zeros(1,1);
for j = 1 : z
n_nonblack = numel(find(data(:,:,j) > 0));
if(n_nonblack > 70)
frames(idx,1) = j;
idx = idx + 1;
end
end
% for j = z : -1 : 1
% n_nonblack = numel(find(data(:,:,j) > 0));
% if(n_nonblack > 50)
% fprintf('%s: %d\n ','number: ', n_nonblack);
% en = j;
% break;
% end
% end
c = 0;
[nrow, ncol] = size(frames);
step = round(nrow/11);
% fprintf('%s: %d \n', 'nrow', nrow);
% fprintf('%s: %d\n ','st: ', frames(1, 1));
% fprintf('%s: %d\n ','end: ', frames(nrow, 1));
%disp(frames);
for k = 1 : step : step*10
%fprintf('%d ', k);
fprintf('%d ', frames(k, 1));
type = '.png';
filename = strcat(id, '_', int2str(c), type); % BraTS19_2013_2_1_seg_flair_c.png
outpath = convertCharsToStrings(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(:,:,frames(k, 1))))));
% M = max(cp_data(:));
% disp(M);
imwrite(cp_data, outpath);
c = c+ 1;
end
end