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
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
Thank you.:-)
Jan
2017년 4월 5일
You are welcome.
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?
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...
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?
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.
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)
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
