Q:

Storing the new format of converted Image

I have a folder which is full of nifti images and I am writing my code in shell script. I want to read all images, and then convert each of them to jpg format with med2image library and then store it with the original name. Here is my code
for f in $(ls ./T1W/*.nii);  do med2image -i $f -d out -o  $f.jpg -s -1; done

However, I get the following error though I have an empty folder(its name is out) 
FileNotFoundError: [Errno 2] No such file or directory: 'out//./T1W/sub-10235_T1w.nii-slice000.jpg'

What should I do?
Thanks!

A:

I solved it by:
         for f in .nii; do
         filename=${f%.}
         med2image -i $filename.nii -d ./out -o $filename.jpg -s -1 
         done

