【ADNI】对 nii 3D 数据进行裁剪(Matlab)待完善...

crop_ADNI_GM.m

function num_list = crop_ADNI_GM(filelistname, save_path, label)
%%%%
%% 脚本说明
% 1)对ADNI-825灰质的3D nii图像进行裁剪
% 2)裁剪部分:没有信息或信息量很少的部分
% 3)裁剪要求:得到一个3D方阵;nii.hdr.dime.dim = [3,112,112,112,1,1,1,1];中的112就是方阵的规格,由(6:117,17:128,6:117);确认
% 4)命名要求:
% 
% gray matter
% AD: 199 samples;
% NC: 230 samples;
% uMCI: 130 samples;
% pMCI: 164 samples;
% sMCI: 99 samples;
% 
% 此处所需数据:pMCI + sMCI = 164 + 99 = 263
% 分类类标:
% AD vs NC --> label AD = 1, label NC = 0
% pMCI vs sMCI --> label pMCI = 1, label sMCI = 0
% 
% 调用函数:
% num_list = crop_ADNI_GM('./825_Subject_AD/AD_gray_matter.txt', './NiftyNet_dataset/AD/', 1)
% num_list = crop_ADNI_GM('./825_Subject_NC/NC_gray_matter.txt', './NiftyNet_dataset/ND/', 0)
% num_list = crop_ADNI_GM('./825_subject_pMCI/pMCI_gray_matter.txt', './NiftyNet_dataset/pMCI/', 1)
% num_list = crop_ADNI_GM('./825_subject_sMCI/sMCI_gray_matter.txt', './NiftyNet_dataset/sMCI/', 0)

    %%
    % filelistname = './825_Subject_AD/AD_gray_matter.txt';
    fpn = fopen(filelistname,'rt');
    sbj_counter = 0;
    while feof(fpn) ~= 1
        sbj_counter = sbj_counter + 1;
        filelist(sbj_counter,1)={fgetl(fpn)};
    end

    %%
    % label = 1;
    % offset_num = 463;
    offset_num = 0;
    % save_path = './NiftyNet_dataset/AD/';
    for i = 1 : sbj_counter
       filename = filelist{i,1};
       disp(filename);
       nii = load_nii(filename); 
       nii.img = nii.img(6:117,17:128,6:117);
       nii.hdr.dime.dim = [3,112,112,112,1,1,1,1];
       save_nii(nii,strcat(save_path, 'T1_S',num2str(i + offset_num,'%03d'),'.nii'))
       nii.img = reshape(label, [1 1 1]);
       nii.hdr.dime.dim = [3,1,1,1,1,1,1,1];
       label_filename = strcat(save_path, 'S',num2str(i + offset_num,'%03d'),'_label','.nii');
       save_nii(nii,label_filename);
    end
    
    num_list = sbj_counter;
end

call_crop_ADNI_GM.m

clc;
clear all;

% 调用函数:
AD_num_list = crop_ADNI_GM('./825_Subject_AD/AD_gray_matter.txt', './NiftyNet_dataset/AD/', 1);
NC_num_list = crop_ADNI_GM('./825_Subject_NC/NC_gray_matter.txt', './NiftyNet_dataset/NC/', 0);
pMCI_num_list = crop_ADNI_GM('./825_subject_pMCI/pMCI_gray_matter.txt', './NiftyNet_dataset/pMCI/', 1);
sMCI_num_list = crop_ADNI_GM('./825_subject_sMCI/sMCI_gray_matter.txt', './NiftyNet_dataset/sMCI/', 0);

AD_gray_matter.txt

【ADNI】对 nii 3D 数据进行裁剪(Matlab)待完善..._第1张图片

裁剪成 112 x 112 x 112 的nii数据并附有相应的类标:

【ADNI】对 nii 3D 数据进行裁剪(Matlab)待完善..._第2张图片

 

 

 

你可能感兴趣的:(【医疗图像处理】)