Automate for multiple .nii file (generating slices)
Closed this issue · 3 comments
Hi
I am trying to create slices from .nii file and automate the process in python. i am able to create slices using the below commands from Linux command prompt: (but one by one). But I would like to automate the process. But it's not working.
Command:
med2image -i '3dNewImage_mask_200.nii.gz' -d 'Downloads/NewTest/200' -o image.jpg -s -1 sliceToConvert: -1
I am trying to automate using below from jupyter notebook
import subprocess
file_name_list = glob.glob('/Downloads/test/*.nii.gz')
pathtosave = '/Downloads/NewTest/'
for i in range(5):
newpath = pathtosave + str(i)
print(file_name_list[i])
print(newpath)
os.system("/nfs/s-iibi54/users/skuanar/Downloads/med2image-master/med2image/med2image.py -i file_name_list[i] -d newpath -o image.jpg -s -1")
Your python syntax in the call to os.system
is incorrect. It should be something like:
os.system("/nfs/s-iibi54/users/skuanar/Downloads/med2image-master/med2image/med2image.py -i %s -d %s -o image.jpg -s -1" % (file_name_list[i], newpath))
Hi,
Thank you. Updated my script. BUt it's now working ... would you please advise me
pathtosave = '/Downloads/test/Testing/testing/'
for i in range(5):
#newpath = pathtosave + str(i)
newpath = os.path.join(pathtosave, str(i), "")
print(file_name_list[i])
print(newpath)
os.mkdir(newpath)
os.system("Downloads/med2image-master/med2image/med2image.py -i %s -d %s -o image.jpg -s -1" % (file_name_list[i], newpath))
output
/Downloads/test/shiba3dNewImage_mask_1.nii.gz
/Downloads/test/Testing/testing/0/
/Downloads/test/shiba3dNewImage_mask_7.nii.gz
/Downloads/test/Testing/testing/1/
/Downloads/test/shiba3dNewImage_mask_13.nii.gz
/Downloads/test/Testing/testing/2/
/Downloads/test/shiba3dNewImage_mask_15.nii.gz
/Downloads/test/Testing/testing/3/
/Downloads/test/shiba3dNewImage_mask_20.nii.gz
/Downloads/test/Testing/testing/4/
But the script is not making any jpeg files ?
But I wrote a different unix script separately and it's working. But the above python script is not working. Please advice me i am making any mistake on above python script
Hi,
It's working now.
I used "/Downloads/med2image-master/bin/med2image" in stead of Downloads/med2image-master/med2image/med2image.py in os.system("Downloads/med2image-master/med2image/med2image.py -i %s -d %s -o image.jpg -s -1" % (file_name_list[i], newpath))
and it worked.
Thank you