How to loop all slice locations from a image volume as a single column vector?

조회 수: 1 (최근 30일)
Hello, I am reading DICOM images from a folder and want to read all image slice locations such that I can have all slice locations as a column vector (I have 71 slices, so want to have 71 slice locations). Below is my attempt but could not able to figure out the way, can anyone help me?
%%
close all; clear; clc;
%%
% List all files in the folder
Files = dir('/etc/*');
for k = 1 : length(Files)
baseFileName = Files(k).name;
fullFileName = fullfile(Files(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
end
%%
info = dicominfo(fullFileName);
slLoc = info.SliceLocation; % this will throw the slice location of the last Dicom image
% I want to write slLoc in a column vector such that all image slice locations are listed

채택된 답변

Voss
Voss 2022년 6월 28일
편집: Voss 2022년 6월 28일
Move the last two lines inside the loop and assign info.SliceLocation to the kth element of slLoc:
%%
close all; clear; clc;
%%
% List all files in the folder
Files = dir('/etc/*');
% slLoc = zeros(numel(Files),1); % pre-allocate slLoc
slLoc = cell(numel(Files),1); % pre-allocate slLoc
for k = 1:numel(Files)
baseFileName = Files(k).name;
fullFileName = fullfile(Files(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
info = dicominfo(fullFileName);
% slLoc(k,1) = info.SliceLocation;
slLoc{k,1} = info.SliceLocation;
end
I don't know what class of data SliceLocation will be, so I've put it in a cell array there. Maybe it can be a numeric array or a string array.
  댓글 수: 8
Voss
Voss 2022년 6월 29일
You're welcome! Glad you got it working!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 DICOM Format에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by