Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Sublobar stuff
- clear
- % to save masked PRM data you will use:
- main_folder = 'N:\photvedt\prm_testing';
- str = main_folder;
- cd(main_folder)
- addpath(genpath('N:\photvedt\NIfTI_20140122'))
- addpath('N:\photvedt\prm_testing','N:\photvedt\prm_testing\!not_cases','N:\mummy\sarp3_vdp_analysis')
- sarps_folder = struct2cell(dir(main_folder));
- sarps_size = size(sarps_folder);
- masked_PRM_map = zeros(sarps_size(2)-3,5);
- name_index = 1;
- study_number = 4;
- while study_number <= sarps_size(2);
- arg = sarps_folder{1,study_number} % This is the name of the given SARP
- mask_arg = regexprep(arg,'sarp_',''); % This extracts the number from arg
- % Put the mask files here
- mask_folder = strcat('N:\mummy\sarp3_vdp_analysis\80-811-', mask_arg,'\sublobe\bl');
- cd(mask_folder);
- addpath(mask_folder);
- lobe_mask = analyze75read('ZUNU_vida-sublobes'); % This will vary for each SARP
- interior_folder = strcat(str,'\', arg,'\', arg, '\T0\TopPRM_E2I'); % This is the name for the folder that contains each of the SARP files for each metric
- cd(interior_folder);
- addpath(interior_folder);
- files_dir = dir('*.mhd');
- sizes = size(files_dir);
- files_struct = struct2cell(files_dir);
- files_struct_t = files_struct.'; % Take the transpose for my conveinece in writing the code.
- file_name_cell = files_struct_t(1:sizes(1)); %This is a cell structure of the files in the SARP subject folder
- while name_index <= length(files_dir)
- file_name = file_name_cell(1,name_index); % This picks the filename in the file_name_cell structure
- file_array = readMHD(file_name{1}); % Numerical matrix of the values at each voxel
- NaN_file = isnan(file_array); % Logical matrix that gives a 1 if the voxel location is not a number
- initial_lung_mask = zeros(size(lobe_mask)); % This is the intial mask in its unoriented orientation. The next few steps adjust the orientation to line up correctly.
- initial_lung_mask(lobe_mask > 0) = 1;
- lung_mask_90deg = imrotate(initial_lung_mask, 90);
- flip_lung_mask_x = flip(lung_mask_90deg,1);
- lung_mask = flip(flip_lung_mask_x,3); % This is the mask file we want that is oriented correctly with the files they gave us
- lung_mask_size = size(lung_mask);
- file_array_size = size(file_array);
- %Make sure to add the NIFTI Toolkit to your path (This is kind of
- %backwards right now.
- name_loc = cellstr(strcat('data\users\photvedt\CT_Space\', arg,'\', arg));
- name_file = cellstr(strcat('masked_', arg,'.nii'));
- masked_PRM_name_cell = [name_file, name_loc]; %PUT CASE NAME FILE ITERATION THING, Pretty sure this is the problem right now.
- % masked_PRM_name = struct2cell(masked_PRM_name_cell);
- make_nii(masked_PRM_map);
- save_nii(masked_PRM_map, masked_PRM_name_cell(1));
- %to do registration
- name_out = fullfile('N:\photvedt\MaskedCTSpace', 'RegisteredPRM_data.nii.gz'); % can change name to whatever you want
- Warp_file = strcat('N:\mummy\sarp3_vdp_analysis\80-811-', mask_arg ,'\nii\mri_bl') % 'PUT LOCATION OF FILE ENDING IN 1Warp.nii.gz' %this will be in nii file in davids folder
- matfile = strcat('N:\mummy\sarp3_vdp_analysis\80-811-', mask_arg ,'\nii\mri_bl') % put location +name of file ending in 0GenericAffine.mat, will also be in davids nii folder for subject
- antsfolder = 'export\home\users\kbanowetz\scripts';
- cd antsfolder
- system(['antsApplyTransforms -d 3 1 -i ' mask ' -o ' name_out ' -n multilabel -r ' Warp_file ' -t ' matfile])
- load_nii(masked_PRM_name_cell(1));
- end
- study_number = study_number + 1;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement