Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Performs nonrigid registration
- local rigid_folder = [[D:\data\MPhys2019\PETCT-HN\RIGIDCODE5 RESULTS\]]; --Folder that contains rigidly registered images
- local nonrigid_folder = [[D:\data\MPhys2019\PETCT-HN\RIGIDCODE5 RESULTS\nonrigid\]]; --Folder you want to save nonrigid scans to
- local oldmethod_file = io.open (nonrigid_folder .. "Niftyregf3d_old2.txt", "w") --Contains list of packs registered with old niftyreg
- local newmethod_file = io.open (nonrigid_folder .. "Niftyregf3d_new2.txt", "w") --List of packs registered with new niftyreg
- local function scandir(directory)
- local i, t, popen = 0, {}, io.popen
- for filename in popen('dir "'..directory..'" /o:n /b'):lines() do
- if string.find(filename, ".pack") then
- i = i + 1
- t[i] = filename
- end
- end
- return t
- end
- local t = scandir(rigid_folder);
- --t = {'401227364.pack'}
- numpacks_done= 0
- t1 = os.time()
- for k,patientpack in ipairs(t) do
- patientpack_new= patientpack:gsub(".pack","")
- loadpack( rigid_folder .. patientpack )
- for i=3,5,2 do --Want to register scan3 and scan5 to scan 1
- --Perform non-rigid registration
- t2= os.time()
- wm.Scan[i]:niftyreg_f3d(wm.Scan[1], nil, [[-ln 5 -be 0.05 -jl 0.0001 -maxit 800 ]]) --old niftyregf3d
- --newmethod_file:write(patientpack_new.."\n")
- if( wm.Scan[i].InverseWarp==nil ) then --if the old one doesn't work, it sets the InverseWarp to empty
- t2= os.time()
- wm.Scan[i]:niftyreg_f3d(wm.Scan[1], nil, [[-ln 5 -be 0.05 -jl 0.0001 -maxit 800 -new]]) -- New niftyireg algorithm
- newmethod_file:write(patientpack_new.."\n")
- else
- oldmethod_file:write(patientpack_new.."\n")
- end
- t3= os.time()
- print(('%s'):format(patientpack).. ',' ..os.difftime(t3, t2) .."\n") --Time taken for nonrigid registration
- --wm.Scan[i]:niftyreg_f3d(wm.Scan[1])
- --Apply the result of the registration to the PET signal
- wm.Scan[i+1].InverseWarp = wm.Scan[i].InverseWarp
- -- Puts scan[i] in grid of scan 1
- wm.Scan[i]= wm.Scan[i]:as(wm.Scan[1])
- -- Puts scan[i+1] in grid of scan 1
- wm.Scan[i+1]= wm.Scan[i+1]:as(wm.Scan[1])
- end
- numpacks_done= numpacks_done+1
- savepack(nonrigid_folder .. patientpack) --Saves pack
- end
- --time_file:write(os.difftime(os.time(), t1)) --Writes to time_file the time in seconds the code took to run
- io.close(oldmethod_file)
- io.close(newmethod_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement