Clear Filters
Clear Filters

Cannot open file anymore when converting Nifti to DICOM

27 views (last 30 days)
YaaW
YaaW on 5 Aug 2024 at 9:58
Answered: Karl on 5 Aug 2024 at 14:10
I have a script where I convert MRI nifti files to DICOM. This used to work but now I get an error when trying to create a new folder and saving the converted files into that folder:
First steps work (Part I):
%% load data
% REVISIT - adapt all text between 'apostrophes'
patientID = 'patient180'; % this is the folder with the specific patient data
patientIn = fullfile('7Tseg_Brainlab', patientID); % this is the folder where the patient folders are in
patientFolder = fullfile... % this is the whole path to the patientIn folder
('here is whole path',patientIn);
addpath(genpath(patientIn));
dicom_template = '00501_3D_TSE_0.7mm'; % this is the original dicom that is used for the new dicom header
Then with this part I get an error (Part II):
% note: the [space] before the second ' after the names is necessary,
% otherwise you will get an error
cmdNiftiToDicom = ['niftitodicom.exe -o' patientFolder '\LmSTN ' patientFolder '\7T2LRmSTN.nii.gz ' patientFolder '\00501_3D_TSE_0.7mm\00001.dcm --sagittal ' '--series-description LmSTN '];
statusNiftiToDicom = system( cmdNiftiToDicom );
cmdNiftiToDicom = ['niftitodicom.exe -o' patientFolder '\RmSTN ' patientFolder '\7T2LRmSTN.nii.gz ' patientFolder '\00501_3D_TSE_0.7mm\00001.dcm --sagittal ' '--series-description RmSTN '];
statusNiftiToDicom = system( cmdNiftiToDicom);
So what I want is 2 folders, named 'LmSTN' and 'RmSTN'. This used to work and now I get the error saying 'Cannot open file', but I do use the correct path.

Answers (1)

Karl
Karl on 5 Aug 2024 at 14:10
Check whether the values of cmdNiftiToDicom correspond to commands that you can run outside of MATLAB.
Do you need a space after the -o in the character arrays used for command construction, so 'niftitodicom.exe -o ' (space at end) rather than 'niftitodicom.exe -o' (no space at end)?

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!