123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- function [ctcell,ct_xmesh,ct_ymesh,ct_zmesh] = dicomrt_loadct(filename,sorting)
- error(nargchk(1,2,nargin))
- if exist('sorting')==0
- sorting=1;
- end
- nlines=dicomrt_nASCIIlines(filename);
- if nlines>1
- disp('Loading CT slice information ...');
- [filelist,xlocation,ylocation,zlocation,modifUID,user_request] = dicomrt_loadctlist(filename);
- if user_request==1;
- return
- end
- disp('CT slice information loaded.');
- if sorting==1
-
- disp('Sorting CT slices ...');
- [modifZ,user_request]=dicomrt_sortct(filelist,xlocation,ylocation,zlocation,filename);
- if user_request==1;
- return
- end
- disp('CT slices sorted.');
- else
- modifZ=0;
- modifUID=0;
- end
- if modifZ~=0 | modifUID~=0
- filename_sorted=[filename,'.sort.txt'];
- else
- filename_sorted=filename;
- end
- else
- disp('Loading one image. Zmesh will have no sense. Slice position can be loaded using dicominfo.');
- filename_sorted=filename;
- end
- CToffset=1000;
- nct=0;
- case_study_info=cell(1);
- disp('Loading ct volume ...');
- h = waitbar(0,['Loading progress:']);
- set(h,'Name','dicomrt_loadct: loading CT images');
- fid=fopen(filename_sorted);
- while (feof(fid)~=1);
- clear info_temp temp
- nct=nct+1;
- nctcheck=nct;
- ct_file_location{1,nct}=fgetl(fid);
- if isnumeric(ct_file_location{1,nct}), nct=nct-1; break, end
-
- temp=dicomread(deblank(ct_file_location{1,nct}));
- dictFlg = checkDictUse;
- if dictFlg
- info_temp=dicominfo(deblank(ct_file_location{1,nct}),'dictionary', 'ES - IPT4.1CompatibleDictionary.mat');
- else
- info_temp=dicominfo(deblank(ct_file_location{1,nct}));
- end
- zmesh(nct)=info_temp.ImagePositionPatient(3);
-
- if isfield(info_temp,'RescaleSlope')~=0 | isfield(info_temp,'RescaleIntercept')~=0
- temp=double(temp)*info_temp.RescaleSlope+info_temp.RescaleIntercept+CToffset;
- else
- warning('dicomrt_loadct: no DICOM Rescale data were found. Assuming RescaleSlope = 1, RescaleIntercept = 0 and CToffset = 1000');
- temp=double(temp);
- end
-
- case_study_info{nct}=info_temp;
- case_study(:,:,nct)=uint16(temp);
- waitbar(nct/nlines,h);
- end
- zmesh=dicomrt_makevertical(zmesh);
- fclose(fid);
- if nctcheck~=nct;
- warning('dicomrt_loadct: End of file was prematurely reached. Check the expected dimensions of your data. It may be OK to continue');
- end
- [PatientPositionCODE]=dicomrt_getPatientPosition(info_temp);
- if PatientPositionCODE == 1 | PatientPositionCODE == 2
- min_x=info_temp.ImagePositionPatient(1);
- pixel_spacing_x=info_temp.PixelSpacing(1);
- min_y=info_temp.ImagePositionPatient(2);
- pixel_spacing_y=info_temp.PixelSpacing(2);
- [xmesh] = dicomrt_create1dmesh(min_x,pixel_spacing_x,size(temp,2),0);
- [ymesh] = dicomrt_create1dmesh(min_y,pixel_spacing_y,size(temp,1),0);
- else
- max_x=info_temp.ImagePositionPatient(1);
- pixel_spacing_x=info_temp.PixelSpacing(1);
- max_y=info_temp.ImagePositionPatient(2);
- pixel_spacing_y=info_temp.PixelSpacing(2);
- [xmesh] = dicomrt_create1dmesh(max_x,pixel_spacing_x,size(temp,1),1);
- [ymesh] = dicomrt_create1dmesh(max_y,pixel_spacing_y,size(temp,2),1);
- end
- ct_zmesh=dicomrt_mmdigit(zmesh*0.1,7);
- ct_ymesh=dicomrt_mmdigit(ymesh*0.1,7);
- ct_xmesh=dicomrt_mmdigit(xmesh*0.1,7);
- disp('Loading complete ...');
- if PatientPositionCODE == 1
- disp('dicomrt_loadct: Patient Position is Head First Supine (HFS).');
- elseif PatientPositionCODE == 2
- disp('dicomrt_loadct: Patient Position is Feet First Supine (FFS).');
- elseif PatientPositionCODE == 3
- disp('dicomrt_loadct: Patient Position is Head First Prone (HFP).');
- elseif PatientPositionCODE == 4
- disp('dicomrt_loadct: Patient Position is Feet First Prone (FFP).');
- else
- warning('Unable to determine Patient Position');
- PatientPosition=input('dicomrt_loadct: Please specify Patient Position: HFS(default),FFS,HFP,FFP: ','s');
- if isempty(PatientPosition)==1
- PatientPosition='HFS';
- end
- if strcmpi(PatientPosition, 'HFS')
- PatientPositionCODE = 1;
- elseif strcmpi(PatientPosition, 'FFS')
- PatientPositionCODE = 2;
- elseif strcmpi(PatientPosition, 'HFP')
- PatientPositionCODE = 3;
- elseif strcmpi(PatientPosition, 'FFP')
- PatientPositionCODE = 4;
- end
- end
- ctcell=cell(3,1);
- ctcell{1,1}=case_study_info;
- ctcell{2,1}=case_study;
- ctcell{3,1}=[];
- close(h);
- pack
|