フィルターのクリア

How can I locate dicom images?

2 ビュー (過去 30 日間)
Tomislav
Tomislav 2012 年 11 月 13 日
So now I have:
[filename, pathname] = uigetfile();
set(handles.edit5, 'String', pathname);
img = zeros(165,127,168,'uint8');
for ii = 1:168;
img(:,:,ii) = dicomread([pathname '\' num2str(ii,'%04i') '.dcm']);
end;
And it only works if there are exactly 168 images (165x127 pixels) in the folder and if they are numbered as: 0001, 0002, 0003, and so on. And it stores it as a 3D matrix name img.
How can I make code that it works with any number of dicom images of any size and any name and that it stores them as now, in 3D matrix called img.
Thanks.

採用された回答

Jan
Jan 2012 年 11 月 13 日
編集済み: Jan 2012 年 11 月 13 日
[filename, pathname] = uigetfile();
if ~ischar(filename)
return;
end
set(handles.edit5, 'String', pathname);
fileList = dir(fullfile(pathname, '*.dcm'));
fileList = fileList(not([fileList.isdir]));
nFile = numel(fileList);
imgC = cell(1, nFile);
for ii = 1:nFile;
imgC{ii} = dicomread(fullfile(pathname, fileList(ii).name));
end
Of course you can store pictures in a 3D-array only, if they all have the same size. If this is true:
imgSize = size(imgC{1});
if all(cellfun('size', imgC, 1) == imgSize(1)) && ...
all(cellfun('size', imgC, 2) == imgSize(2))
img = cat(3, imgC{:});
else
error('Pictures have different sizes.');
end
  1 件のコメント
Tomislav
Tomislav 2012 年 11 月 13 日
Awesome. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDICOM Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by