Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. %% Sublobar stuff
  2. clear
  3.  
  4. % to save masked PRM data you will use:
  5.  
  6. main_folder = 'N:\photvedt\prm_testing';
  7. str = main_folder;
  8. cd(main_folder)
  9. addpath(genpath('N:\photvedt\NIfTI_20140122'))
  10. addpath('N:\photvedt\prm_testing','N:\photvedt\prm_testing\!not_cases','N:\mummy\sarp3_vdp_analysis')
  11.  
  12. sarps_folder = struct2cell(dir(main_folder));
  13. sarps_size = size(sarps_folder);
  14. masked_PRM_map = zeros(sarps_size(2)-3,5);
  15.  
  16. name_index = 1;
  17. study_number = 4;
  18.  
  19. while study_number <= sarps_size(2);
  20. arg = sarps_folder{1,study_number} % This is the name of the given SARP
  21. mask_arg = regexprep(arg,'sarp_',''); % This extracts the number from arg
  22.  
  23. % Put the mask files here
  24. mask_folder = strcat('N:\mummy\sarp3_vdp_analysis\80-811-', mask_arg,'\sublobe\bl');
  25. cd(mask_folder);
  26. addpath(mask_folder);
  27.  
  28. lobe_mask = analyze75read('ZUNU_vida-sublobes'); % This will vary for each SARP
  29.  
  30. 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
  31. cd(interior_folder);
  32. addpath(interior_folder);
  33.  
  34. files_dir = dir('*.mhd');
  35. sizes = size(files_dir);
  36. files_struct = struct2cell(files_dir);
  37. files_struct_t = files_struct.'; % Take the transpose for my conveinece in writing the code.
  38. file_name_cell = files_struct_t(1:sizes(1)); %This is a cell structure of the files in the SARP subject folder
  39.  
  40. while name_index <= length(files_dir)
  41.  
  42. file_name = file_name_cell(1,name_index); % This picks the filename in the file_name_cell structure
  43. file_array = readMHD(file_name{1}); % Numerical matrix of the values at each voxel
  44. NaN_file = isnan(file_array); % Logical matrix that gives a 1 if the voxel location is not a number
  45.  
  46. 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.
  47. initial_lung_mask(lobe_mask > 0) = 1;
  48. lung_mask_90deg = imrotate(initial_lung_mask, 90);
  49. flip_lung_mask_x = flip(lung_mask_90deg,1);
  50. 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
  51. lung_mask_size = size(lung_mask);
  52. file_array_size = size(file_array);
  53.  
  54. %Make sure to add the NIFTI Toolkit to your path (This is kind of
  55. %backwards right now.
  56. name_loc = cellstr(strcat('data\users\photvedt\CT_Space\', arg,'\', arg));
  57. name_file = cellstr(strcat('masked_', arg,'.nii'));
  58.  
  59.  
  60. masked_PRM_name_cell = [name_file, name_loc]; %PUT CASE NAME FILE ITERATION THING, Pretty sure this is the problem right now.
  61. % masked_PRM_name = struct2cell(masked_PRM_name_cell);
  62. make_nii(masked_PRM_map);
  63. save_nii(masked_PRM_map, masked_PRM_name_cell(1));
  64.  
  65. %to do registration
  66. name_out = fullfile('N:\photvedt\MaskedCTSpace', 'RegisteredPRM_data.nii.gz'); % can change name to whatever you want
  67. 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
  68. 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
  69.  
  70. antsfolder = 'export\home\users\kbanowetz\scripts';
  71. cd antsfolder
  72.  
  73. system(['antsApplyTransforms -d 3 1 -i ' mask ' -o ' name_out ' -n multilabel -r ' Warp_file ' -t ' matfile])
  74.  
  75. load_nii(masked_PRM_name_cell(1));
  76. end
  77.  
  78.  
  79. study_number = study_number + 1;
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement