Can we read dicom files without extension using the dicomread function?

I have 71 image slices and the idea is to make an image volume using these slices. I tried using the following:
close all; clear; clc
%%
Folder = '/etc/';
filenames = fullfile(Folder,'Z*'); % files names are Z01, Z02, ....., Z75
findDir = dir(filenames);
total_Im = numel(filenames);
%%
for n = 1:total_Im
f = fullfile(Folder,filenames(n).name);
dm_images = dicomread(f);
figure(n)
imshow(dm_images)
end
% How can I read these files without extension and make a single image
% volume?

 Accepted Answer

Store the read images in a 3D array. That way you will have the entire volume in one variable, allowing you to do further processing as you need to.
clear dm_images
for n = 1:total_Im
f = fullfile(Folder,filenames(n).name);
dm_images(:, :, n) = dicomread(f);
end

4 Comments

I tried the following and this did not work - where did I make a miistake?
It threw an error of this type: Dot indexing is not supported for variables of this type.
Error in testhundred (line 13)
f = fullfile(Folder,filenames(n).name);
close all; clear all; clc
%%
Folder = '/etc/';
filenames = fullfile(Folder,'*');
findDir = dir(filenames);
total_Im = length(filenames);
%%
clear dm_images
for n = 1:total_Im
f = fullfile(Folder,filenames(n).name);
dm_images(:, :, n) = dicomread(f);
end
I didn't read your code carefully enough. I had assumed (based on how you treat it) that filenames would be output of the dir call, instead of the input to it. Simply exchange it with findDir to prevent the error.
You can also remove that first line of code.
Not sure I understand - I tried to do the following but the code throws an error:
close all; clear; clc
%%
% List all files in the folder
files = dir('/etc/*');
total_Im = length(files);
%%
% Read the file names
for i = 1:total_Im
filename = files(i);
filename.name
end
%%
% Read the images in a 3D array
for i = 1:total_Im
filename = files(i);
dm_images(:, :, i) = dicomread(filename);
end
Error is here:
Reference to non-existent field 'Filename'.
Error in dicomread>newDicomread (line 184)
filename = msgname.Filename;
Error in dicomread (line 91)
[X, map, alpha, overlays] = newDicomread(msgname, frames, useVRHeuristic);
Error in testhundred (line 20)
dm_images(:, :, i) = dicomread(filename);
Any hints on this? Thank you in advance.
I would suggest using the debugger to go through your code line by line. Then you would discover your first loop doesn't do anything. You would also find out that your file name variable doesn't actually contain a file name, but is instead a struct. That makes dicomread assume it is a dicominfo struct.
Folder = '/etc/';
findDir = fullfile(Folder,'*');
filenames = dir(findDir);
total_Im = length(filenames);
clear dm_images
for n = 1:total_Im
f = fullfile(Folder,filenames(n).name);
dm_images(:, :, n) = dicomread(f);
end

Sign in to comment.

More Answers (0)

Asked:

on 28 Jun 2022

Commented:

Rik
on 29 Jun 2022

Community Treasure Hunt

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

Start Hunting!