MATLAB Answers

how to write loop for dicom image

4 views (last 30 days)
mohd akmal masud
mohd akmal masud on 4 Jan 2021
Commented: Rik on 5 Jan 2021
Hi all, i have 10 images start with I40.dcm to I130.dcm.
i try thid command, but failed. anyone can help me?
clear all
P = zeros(256, 256, 10);
for K = 1 : 10
petname = sprintf('I%40d.dcm', K);
P(:,:,K) = dicomread(petname);

Accepted Answer

Rik on 4 Jan 2021
You can either list the file names, or properly create the file name:
%clear all
%^^^^ These are not needed, and especially clear all is a bad idea. Use clear or clearvars instead.
P = zeros(256, 256, 10);
for K = 1 : 10
petname = sprintf('I%d.dcm', K_file);
P(:,:,K) = dicomread(petname);
Rik on 5 Jan 2021
You can first read the dicom image to a temporary variable. Then you can resize it and store it in P.
But are you sure you want to resize the slices? In general you don't want to do that while reading a scan.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!