Problem with sprintf and read DICOM images
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Dear all,
I have CT slices and I would like to load (imread) them to the Workspace. But I always read only one (first) slice (image). This is my code:
for p=1:38
filename = sprintf('C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/000048.dcm',p);
X(:,:,1,p) = dicomread(filename);
I don´t know, where mistake is.
Can you advise me? Thank you for your answers.
採用された回答
There is no format specifier in the format string of sprintf:
sprintf('C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/000048.dcm',p);
This is the same string for all iterations. Perhaps you want:
filename = sprintf('C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/%06d.dcm', p);
12 件のコメント
Veronika
2017 年 4 月 5 日
Okay, it will help, but my first CT scan is 000048.dcm not 000001.dcm. Could I somehow ensure this?
Error using dicomread>getFileDetails (line 1458)
File "C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/000001.dcm" not found.
@Veronika: :-) Then start the loop at 48:
Folder = 'C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/'; % Nicer
for p = 48:86
filename = fullfile(Folder, sprintf('%06d.dcm', p));
X(:, : , 1, p - 47) = dicomread(filename);
end
Or:
for p = 1:38
filename = fullfile(Folder, sprintf('%06d.dcm', p + 47));
X(:, : , 1, p) = dicomread(filename)
end
Veronika
2017 年 4 月 5 日
Thank you.:-)
Jan
2017 年 4 月 5 日
You are welcome.
mohd akmal masud
2017 年 11 月 8 日
HI.. May i know what is the meaning for "p = 48:86" and "for p = 1:38" actually?
if i have 135 slice CT images, what should i writ the value of p?
Walter Roberson
2017 年 11 月 9 日
first_to_read = 48;
last_to_read = 86;
num_to_read = last_to_read - first_to_read + 1;
Now you can use
for file_idx = 1 : num_to_read
img_number = file_idx + first_to_read - 1;
filename = fullfile(Folder, sprintf('%06d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end
in which case file_idx refers to the relative number to read, which can be quite useful for several different reasons.
You could also use
for file_number = first_to_read : last_to_read
file_idx = file_number - first_to_read + 1;
filename = fullfile(Folder, sprintf('%06d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end
which is sometimes easier to read. But in practice it turns out to be easier to work with relative indices in a for loop: when relative indices are used it is not necessary that the values be consecutive:
files_to_read = [48:63 72:78 85]; %does not need to be consecutive
num_to_read = length(files_to_read);
for file_idx = 1 : num_to_read
img_number = files_to_read(file_idx);
filename = fullfile(Folder, sprintf('%06d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end
mohd akmal masud
2017 年 11 月 17 日
編集済み: Walter Roberson
2017 年 11 月 17 日
Dear Walter Roberson,
I used this command to read multiple image CT. i have 135 slice CT images (in format dicom). My first image name start with "CTAC001_CT001.dcm" until "CTAC001_CT135.dcm"
I used this command:
for file_number = first_to_read : last_to_read
file_idx = file_number - first_to_read + 1;
filename = fullfile(Folder, sprintf('%06d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end
Undefined function or variable 'first_to_read'.
But the ERROR appear as below:
Error in trymultipleimages (line 1)
for file_number = first_to_read : last_to_read
Can you help me please...
Walter Roberson
2017 年 11 月 17 日
Notice my lines near the beginning,
first_to_read = 48;
last_to_read = 86;
mohd akmal masud
2017 年 11 月 17 日
編集済み: Walter Roberson
2017 年 11 月 17 日
Meaning that, i have to write like this:
first_to_read = CTAC001_CT001.dcm;
last_to_read = CTAC001_CT135.dcm;
num_to_read = last_to_read - first_to_read + 1;
for file_number = first_to_read : last_to_read
file_idx = file_number - first_to_read + 1;
filename = fullfile(Folder, sprintf('%06d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end
is it correct?
Walter Roberson
2017 年 11 月 17 日
last_to_read = 135;
for file_number = 1 : last_to_read
filename = fullfile(Folder, sprintf('CTAC001_CT%03d.dcm', file_number));
X(:, : , 1, file_number) = dicomread(filename);
if file_number == 1 && last_to_read ~= 1
X(end, end, end, last_to_read) = 0;
end
end
The special test for file_number 1 is a performance optimization to avoid having to grow the array every iteration.
mohd akmal masud
2017 年 11 月 17 日
Dear Walter Roberson,
The code is successfully. I have try for 135 slices CT images and also 135 slices PET images.
But how come to me to show it in figure (i mean use command imshow)
Walter Roberson
2017 年 11 月 17 日
It cannot be shown in a single figure using imshow. imshow() is not suitable for volume visualization.
If you have R2017a or newer, try
volumeViewer( permute(X, [1 2 4 3]) )
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Convert Image Type についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
