First input must be a file name or a file identifier.

16 Ansichten (letzte 30 Tage)
Stelios Fanourakis
Stelios Fanourakis am 10 Mai 2018
Bearbeitet: Guillaume am 10 Mai 2018
I get the error at line
[Img] = DicomReader(theFiles)
and
dicom_header = dicominfo(filename);
The code:
N=15;
img_dir = 'D:\stelios phd files\DesMoines\karadokei\'
filePattern = fullfile(img_dir, '*.dcm');
theFiles = dir(filePattern);
for k= 1:length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(img_dir, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = dicomread(baseFileName);
end
D = squeeze(imageArray)
[Img] = DicomReader(D,N)
  4 Kommentare
Stelios Fanourakis
Stelios Fanourakis am 10 Mai 2018
function Img = DicomReader(filename,N)
dicom_header = dicominfo(filename);
file_names = dir([filename(1) '*']);
Img = zeros([dicom_header.Width, dicom_header.Height, length(file_names)]);
minSliceNo = Inf;
maxSliceNo = 0;
for i = 1:N
dicom_header = dicominfo(file_names(i).name);
if dicom_header.InstanceNumber < minSliceNo
minSliceNo = dicom_header.InstanceNumber;
end
if dicom_header.InstanceNumber > maxSliceNo
maxSliceNo = dicom_header.InstanceNumber;
end
Img(:,:,dicom_header.InstanceNumber) = dicomread(dicom_header);
end
Img = Img(:,:,minSliceNo:maxSliceNo);
end
Stelios Fanourakis
Stelios Fanourakis am 10 Mai 2018
But now I have another problem. Can someone who knows dicom very well please explain me the Instance Number and Acquisition Numbers tags what do they mean and what values can we insert if they are not predefined?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Ameer Hamza
Ameer Hamza am 10 Mai 2018
dir() only return file names, not complete paths. You need to specify the full path to dicomread(), Change the line like this
imageArray = dicomread(fullFileName);

Guillaume
Guillaume am 10 Mai 2018
function Img = DicomReader(filename,N)
Clearly your function expects a filename as the first argument
D = squeeze(imageArray)
[Img] = DicomReader(D,N)
Yet, you give it an imagearray. I don't understand why you expected that to work.
In addition, you're creating the imageArray in the loop but at each iteration you're overwriting the previous imageArray. So after the loop, imageArray is just the last image and you've discarded all the other ones.
  2 Kommentare
Stelios Fanourakis
Stelios Fanourakis am 10 Mai 2018
I corrected everything you suggested but still comes the same error.
imageArray = dicomread(fullFileName);
filename = squeeze(imageArray)
[Img] = DicomReader(filename,N)
imageArray is out of for loop
Guillaume
Guillaume am 10 Mai 2018
Bearbeitet: Guillaume am 10 Mai 2018
The name of the variable is irrelevant. No matter what you call it you are still passing an image to DicomReader, not a filename.
I have no idea what you're trying to do but your code makes no sense. You read images in a loop to immediately discard the images without doing anything with them. After the loop, you're left with the last image only, which you pass to another function which expects a filename not an image.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by