Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Loops through .pack files that have 6 images in and saves all 6 images to nifti files.
- local folder = [[D:\data\MPhys2019\PETCT-HN\26-11\Rigid\BigDoseCropRigid\]]; --This folder contains .pack files
- local folder_nifti= [[D:\data\MPhys2019\PETCT-HN\26-11\Rigid\BigDoseCropRigid\nifti\]]; --Save .nifti files to this folder
- local function scandir(directory)
- local i, t, popen = 0, {}, io.popen
- for filename in popen('dir "'..directory..'" /o:n /b'):lines() do
- i = i + 1
- t[i] = filename
- end
- return t
- end
- local t = scandir(folder);
- --t = {'688912716.pack'} --This overwrites t, use if only want to save one pack
- for k,patientpack in ipairs(t) do
- loadpack( folder .. patientpack )
- patientpack_new= patientpack:gsub(".pack","")
- skip= false
- --Don't want to look at the patients with missing scans
- for i = 1,6 do
- if wm.Scan[i].Data.empty then skip = true
- end
- end
- if not skip then
- for p = 1,6 do --goes through 6 images
- scan_name= ("%s_scan%d"):format(patientpack_new,p) --"patientpack_new_scanp"
- --file_name= ([[D:/data/MPhys2019/PETCT-HN/Test/%s.nii]]):format(scan_name)
- wm.Scan[p]:write_nifty(folder_nifti .. scan_name .. ".nii") --Writes to nifti
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement