Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. --Performs nonrigid registration
  2.  
  3. local rigid_folder = [[D:\data\MPhys2019\PETCT-HN\RIGIDCODE5 RESULTS\]]; --Folder that contains rigidly registered images
  4.  
  5. local nonrigid_folder = [[D:\data\MPhys2019\PETCT-HN\RIGIDCODE5 RESULTS\nonrigid\]]; --Folder you want to save nonrigid scans to
  6.  
  7.  
  8. local oldmethod_file = io.open (nonrigid_folder .. "Niftyregf3d_old2.txt", "w") --Contains list of packs registered with old niftyreg
  9. local newmethod_file = io.open (nonrigid_folder .. "Niftyregf3d_new2.txt", "w") --List of packs registered with new niftyreg
  10.  
  11. local function scandir(directory)
  12.   local i, t, popen = 0, {}, io.popen
  13.   for filename in popen('dir "'..directory..'" /o:n /b'):lines() do
  14.     if string.find(filename, ".pack") then
  15.       i = i + 1
  16.       t[i] = filename
  17.     end
  18.   end
  19.   return t
  20. end
  21.  
  22. local t = scandir(rigid_folder);
  23.  
  24. --t = {'401227364.pack'}
  25.  
  26. numpacks_done= 0
  27. t1 = os.time()
  28. for k,patientpack in ipairs(t) do
  29.   patientpack_new= patientpack:gsub(".pack","")
  30.  
  31.   loadpack( rigid_folder .. patientpack )
  32.  
  33.   for i=3,5,2 do --Want to register scan3 and scan5 to scan 1
  34.  
  35. --Perform non-rigid registration
  36.   t2= os.time()
  37.   wm.Scan[i]:niftyreg_f3d(wm.Scan[1], nil, [[-ln 5 -be 0.05 -jl 0.0001 -maxit 800 ]]) --old niftyregf3d
  38.   --newmethod_file:write(patientpack_new.."\n")
  39.  
  40.   if( wm.Scan[i].InverseWarp==nil ) then --if the old one doesn't work, it sets the InverseWarp to empty
  41.     t2= os.time()
  42.     wm.Scan[i]:niftyreg_f3d(wm.Scan[1], nil, [[-ln 5 -be 0.05 -jl 0.0001 -maxit 800 -new]]) -- New niftyireg algorithm
  43.     newmethod_file:write(patientpack_new.."\n")
  44.   else
  45.     oldmethod_file:write(patientpack_new.."\n")
  46.   end
  47.  
  48.   t3= os.time()
  49.   print(('%s'):format(patientpack).. ',' ..os.difftime(t3, t2) .."\n") --Time taken for nonrigid registration
  50.  
  51.  
  52.  
  53.   --wm.Scan[i]:niftyreg_f3d(wm.Scan[1])
  54. --Apply the result of the registration to the PET signal
  55.   wm.Scan[i+1].InverseWarp = wm.Scan[i].InverseWarp
  56.  
  57. -- Puts scan[i] in grid of scan 1
  58.   wm.Scan[i]= wm.Scan[i]:as(wm.Scan[1])
  59. -- Puts scan[i+1] in grid of scan 1
  60.   wm.Scan[i+1]= wm.Scan[i+1]:as(wm.Scan[1])
  61.  
  62. end
  63. numpacks_done= numpacks_done+1
  64.  
  65. savepack(nonrigid_folder .. patientpack) --Saves pack
  66.  
  67. end
  68.  
  69. --time_file:write(os.difftime(os.time(), t1)) --Writes to time_file the time in seconds the code took to run
  70.  
  71. io.close(oldmethod_file)
  72. io.close(newmethod_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement