MATLAB Answers

Reading DICOM files into Matlab

조회 수: 2(최근 30일)
Lawen Karim
Lawen Karim 2020년 12월 3일
답변: Ajay Neeli 2021년 1월 5일
Hello all, Please can you help me correct the folllowing. I am trying to upload dicom files of mri scans to analyse the T2* over time.
When I load the dicoms it gives me this error:
Error using zeros
Size inputs must be scalar.
Error in ROI_timecourse_DICOM_v2_7_TS (line 30)
im4D=zeros(im4D_info.Rows,im4D_info.Columns,im4D_info.Private_2001_1018,dyns);
The code is as follows
%% Name and path of outcoming and incoming files
%path='/Volumes/DOCS/DATA/studies/';
%cd(path)
ROIcheck=input('Have you saved ROIs to use in this subject? [y/n]: ','s');
ROIcorr=input('Would you like to redo any of the ROIs? [y/n]: ','s');
loadRegisteredData=input('Do you also have registered data from imagej (exported as TIFF)? [y/n]: ','s');
%avg_window=input('Would level of moving average? [0-200]: ');
avg_window = 0; % turn off for now
avg_method=input('Summary method? [median|mean] (leave empty for default): ','s');
[FileName,PathName] = uigetfile({'*','*'},'Input the first DICOM functional image (exported from Osirix)');
im4D_info=dicominfo(strcat(PathName,FileName));
%suffix=strfind(FileName,'.');
% TS - change to not assume .dcm ending
suffix=strfind(FileName,'(');
FileName = FileName(1:suffix(1)-5);
dyns=im4D_info.NumberOfTemporalPositions;
name_dir=dir(strcat(PathName,FileName,'*'));
name_dir=name_dir(1:dyns);
datefile=num2str(char({name_dir.name}));
im4D=zeros(im4D_info.Rows,im4D_info.Columns,im4D_info.Private_2001_1018,dyns);
h=waitbar(0,'Loading Files...');
trigtimes=zeros(dyns,1);
for i=1:dyns
im4D_info_=dicominfo(strcat(PathName,name_dir(i).name));
im4D_info_.BitsAllocated=32;
im4D(:,:,:,i)=im4D_info_.RescaleSlope*dicomread(im4D_info_);
trigtimes(i)=im4D_info_.TriggerTime/1000;
waitbar(i/dyns,h,strcat('Loading Files... ',num2str(round(i/dyns*100)),' %'));
% fprintf(1,'File Name: %s \n',name_dir(i).name); %prints out all the names of loaded files
end
% load registered images if exist
if (loadRegisteredData=='y')
[FileName,PathName] = uigetfile({'*','*'},'Input the first registered functional image (exported from ImageJ as TIFF)');
%suffix=strfind(FileName,'.');
% TS - change to not assume .dcm ending
suffix=strfind(FileName,'_');
dyns=im4D_info.NumberOfTemporalPositions;
name_dir=dir(strcat(PathName,'*.tif','*'));
name_dir=name_dir(1:dyns);
datefile=num2str(char({name_dir.name}));
im4D_reg=zeros(im4D_info.Rows,im4D_info.Columns,im4D_info.Private_2001_1018,dyns);
h=waitbar(0,'Loading Reg Files...');
for i=1:dyns
t = Tiff(strcat(PathName,name_dir(i).name),'r');
im4D_reg(:,:,:,i)=read(t);
close(t);
waitbar(i/dyns,h,strcat('Loading Files... ',num2str(round(i/dyns*100)),' %'));
% fprintf(1,'File Name: %s \n',name_dir(i).name); %prints out all the names of loaded files
end
im4D = im4D_reg;
end
close(h)
fprintf(1,'Total of %d functional files loaded \n',i);
colour_map='rkbmgrkbmgcy';
cd(PathName)
if ((ROIcheck=='n')||(ROIcorr=='y'))
[FileNameA,PathNameA] = uigetfile({'*','*'},'Input the first DICOM anatomical image (exported from Osirix)');
imAnat_info=dicominfo(strcat(PathNameA,FileNameA));
% suffix=strfind(FileNameA,'.');
% TS - account for different path name compared to osirix
suffix=strfind(FileNameA,'(');
FileNameA=FileNameA(1:suffix(1)-1);
dyns=imAnat_info.NumberOfTemporalPositions;
if (dyns==1)
h=waitbar(0,'Loading Files...');
slc=imAnat_info.Private_2001_1018;
name_dir1=dir(strcat(PathNameA,FileNameA,'*'));
name_dir1=name_dir1(1:slc);
for i=1:slc
imAnat(:,:,i)=dicomread(strcat(PathNameA,name_dir2(i).name));
% fprintf(1,'File Name: %s \n',name_dir1(i).name);
waitbar(i/slc,h,strcat('Loading Files... ',num2str(round(i/slc*100)),' %'));
end
close(h)
fprintf(1,'Total of %d anatomical files loaded \n',i);
else
name_dir2=dir(strcat(PathNameA,FileNameA,'*'));
name_dir2=name_dir2(1:dyns);
datefile=num2str(char({name_dir2.name}));
h=waitbar(0,'Loading Files...');
for i=1:dyns
imAnat(:,:,:,i)=dicomread(strcat(PathNameA,name_dir2(i).name));
waitbar(i/dyns,h,strcat('Loading Files... ',num2str(round(i/dyns*100)),' %'));
% fprintf(1,'File Name: %s \n',name_dir1(i).name);
end
close(h)
fprintf(1,'Total of %d anatomical files loaded \n',i);

답변(1개)

Ajay Neeli
Ajay Neeli 2021년 1월 5일
The error seems to be due to the im4D_info MAT file. The size input arguments of zeros function are expected to be scalars each denoting the size of a particular dimension. You may check the im4D_info.Rows, im4D_info.Columns, im4D_info.Private_2001_1018, and dyns variables and their datatypes.
You may also refer to the following ML answers links related to the same error for better clarity.

Community Treasure Hunt

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

Start Hunting!

Translated by