Mehdi
Mehdi

Reputation: 1306

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!

Upvotes: 0

Views: 477

Answers (2)

Mehdi
Mehdi

Reputation: 1306

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

Upvotes: 0

Your code is okay, only need a colon after do, and path for out:

for f in $(ls ./T1W/*.nii); do : med2image -i $f -d ./out -o $f.jpg -s -1; done

Upvotes: 1

Related Questions