How to read a lot of DICOM files with Matlab?

I am using a script which generate a collection of strings in a loop:

'folder1/im1' 
'folder1/im2'
... 
'folder1/im3'

I assign the string to a variable, when I try to execute the img = dicomread(file); function I get the following error:

Error using dicomread>newDicomread (line 164)
The first input argument must be a filename or DICOM info struct.

Error in dicomread (line 80)
[X, map, alpha, overlays] = newDicomread(msgname, frames);

Error in time (line 14)
    img = dicomread(file);

However, using the command line I don't get errors: img = dicomread('folder1/im1').

The code is the next:

    for i=1:6 %six cases
            nameDir = strcat('folder', int2str(i));
            dirData = dir(nameDir);
            dirIndex = [dirData.isdir];
            fileList = {dirData(~dirIndex).name}; % list of files for each directory
            n = size(fileList);
            cd(nameDir);
            for x = 1:n(2)
                    img = dicomread(strcat(pwd(), '/', fileList(x)));
            end
            cd('..');
    end

What could be the error?

Answers


You've figured it out by now, haven't you.

Based on what you've written, you test

img = dicomread('folder1/im1');

when what you are having trouble with is

img = dicomread(file);

You need to actually test the line you are having trouble with. I would recommend:

putting a break point in test.m a the line img = dicomread(file). When you get to that line you can see what file is equal to. Also do whos file to make sure it is of class char and not a cell array or something random.

If you still want help, edit your original post and show the code where you assign those strings to file and tell us what happens when you type img = dicomread(file) at the command prompt.


Need Your Help