Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. -- Loops through .pack files that have 6 images in and saves all 6 images to nifti files.
  2.  
  3.  
  4. local folder = [[D:\data\MPhys2019\PETCT-HN\26-11\Rigid\BigDoseCropRigid\]]; --This folder contains .pack files
  5. local folder_nifti= [[D:\data\MPhys2019\PETCT-HN\26-11\Rigid\BigDoseCropRigid\nifti\]]; --Save .nifti files to this folder
  6.  
  7. local function scandir(directory)
  8.   local i, t, popen = 0, {}, io.popen
  9.   for filename in popen('dir "'..directory..'" /o:n /b'):lines() do
  10.       i = i + 1
  11.       t[i] = filename
  12.   end
  13.   return t
  14. end
  15.  
  16. local t = scandir(folder);
  17.  
  18. --t = {'688912716.pack'} --This overwrites t, use if only want to save one pack
  19.  
  20. for k,patientpack in ipairs(t) do
  21.  
  22.   loadpack( folder .. patientpack )
  23.   patientpack_new= patientpack:gsub(".pack","")
  24.    
  25.     skip= false
  26.  
  27.   --Don't want to look at the patients with missing scans
  28.     for i = 1,6 do
  29.         if wm.Scan[i].Data.empty then skip = true
  30.    
  31.     end
  32.   end
  33.  
  34.   if not skip then
  35.    
  36.       for p = 1,6 do --goes through 6 images
  37.        
  38.         scan_name= ("%s_scan%d"):format(patientpack_new,p) --"patientpack_new_scanp"
  39.        
  40.        
  41.         --file_name= ([[D:/data/MPhys2019/PETCT-HN/Test/%s.nii]]):format(scan_name)
  42.         wm.Scan[p]:write_nifty(folder_nifti .. scan_name .. ".nii") --Writes to nifti
  43.     end    
  44.        
  45.   end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement