dicomrt_loadctlist.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. function [filelistAXIAL,xlocationAXIAL,ylocationAXIAL,zlocationAXIAL,change,user_option] = dicomrt_loadctlist(filename)
  2. % dicomrt_loadctlist(filename)
  3. %
  4. % Parse CT data set specified in filename. If more than one study are found within the CT data set
  5. % the user can select a study and dicomrt_loadctlist return a filelist and x,y,z coordinates of the
  6. % selected CT subset
  7. %
  8. % filename contains a list of CT slices to import
  9. %
  10. % change is 1 if any change to the filelist have been done, 0 otherwise
  11. % user_option is 1 if the user select not to continue with the program, 0 otherwise
  12. %
  13. % Example:
  14. % [list,x,y,z,change,user_option]=dicomrt_loadctlist(filename)
  15. %
  16. % with filename containint the following:
  17. % ct1 (group1)
  18. % ct2 (group2)
  19. % ct3 (group1)
  20. % ct4 (group2)
  21. %
  22. % if the user select one of them (e.g. group1):
  23. % list= contain only ct1 and ct3,
  24. % x= xlocation of ct1 and ct3 ,
  25. % y= ylocation of ct1 and ct3 ,
  26. % z= zlocation of ct1 and ct3 ,
  27. % change= 1,
  28. % user_option= 0
  29. %
  30. % See also dicomrt_loaddose dicomrt_loadct dicomrt_sortct
  31. %
  32. % Copyright (C) 2002 Emiliano Spezi (emiliano.spezi@physics.org)
  33. % Retrieve the number of images
  34. nlines=dicomrt_nASCIIlines(filename);
  35. % Get CT images and create 3D Volume
  36. fid=fopen(filename);
  37. nct=0;
  38. counter=0;
  39. % Initialize variable
  40. filelist=' ';
  41. studyUIDlist=' ';
  42. listUID=' ';
  43. imagetype=' ';
  44. user_option=0;
  45. % Progress bar
  46. h = waitbar(0,['Loading progress:']);
  47. set(h,'Name','dicomrt_loadctlist: loading CT objects tags');
  48. %loop until the end-of-file is reached and build 3D CT matrix
  49. while (feof(fid)~=1);
  50. nct=nct+1; % counting
  51. nctcheck=nct; % check for eof
  52. ct_file_location{1,nct}=fgetl(fid);
  53. if isnumeric(ct_file_location{1,nct}), nct=nct-1, break, end %end of line reached
  54. dictFlg = checkDictUse;
  55. if dictFlg
  56. info_temp=dicominfo(ct_file_location{1,nct}, 'dictionary', 'ES - IPT4.1CompatibleDictionary.mat');
  57. else
  58. info_temp=dicominfo(ct_file_location{1,nct});
  59. end
  60. xlocation(nct)=info_temp.ImagePositionPatient(1);
  61. ylocation(nct)=info_temp.ImagePositionPatient(2);
  62. zlocation(nct)=info_temp.ImagePositionPatient(3);
  63. xlocation=xlocation';
  64. ylocation=ylocation';
  65. zlocation=zlocation';
  66. filelist=char(filelist,info_temp.Filename);
  67. if isfield(info_temp,'ImageType')~=1
  68. warning('dicomrt_loadctlist: no DICOM ImageType was found. Assuming AXIAL CT Images');
  69. imagetype='AXIAL';
  70. else
  71. imagetype=char(imagetype,info_temp.ImageType);
  72. end
  73. listUID=char(listUID,info_temp.StudyInstanceUID);
  74. studyUID=info_temp.StudyInstanceUID;
  75. if isequal(studyUID, studyUIDlist(size(studyUIDlist,1),:))==0
  76. studyUIDlist=char(studyUIDlist,studyUID);
  77. end
  78. waitbar(nct/nlines,h);
  79. end
  80. filelist(1,:)=[];
  81. studyUIDlist(1,:)=[];
  82. listUID(1,:)=[];
  83. imagetype(1,:)=[];
  84. if size(studyUIDlist,1)>=2
  85. change=1;
  86. disp(' ');
  87. warning([int2str(size(studyUIDlist,1)),' studies was found among the ct slices you want to import']);
  88. disp(' ');
  89. leave = input('Do you want to leave (Y/N) ? [N] ','s');
  90. if leave == 'Y' | leave == 'y';
  91. user_option=1;
  92. return
  93. else
  94. disp('Available studies:');
  95. for j=1:size(studyUIDlist,1)
  96. disp([int2str(j), ' - ', studyUIDlist(j,:)]);
  97. end
  98. chooseUID = input(['Select a study to be imported from 1 to ',int2str(size(studyUIDlist,1)),': ']);
  99. if isempty(chooseUID)==1 | isnumeric(chooseUID)~=1 | chooseUID>size(studyUIDlist,1)
  100. error('dicomrt_loadctlist: There is no default to this answer or the number to entered is invalid. Exit now !');
  101. user_option=1;
  102. else
  103. filelistUID=' ';
  104. imagetypeUID=' ';
  105. for k=1:size(filelist,1)
  106. if listUID(k,:)==studyUIDlist(chooseUID,:);
  107. counter=counter+1;
  108. filelistUID=char(filelistUID,filelist(k,:));
  109. imagetypeUID=char(imagetypeUID,imagetype(k,:));
  110. xlocationUID(counter)=xlocation(k);
  111. ylocationUID(counter)=ylocation(k);
  112. zlocationUID(counter)=zlocation(k);
  113. end
  114. end
  115. filelistUID(1,:)=[];
  116. imagetypeUID(1,:)=[];
  117. counter=0; % reset counter
  118. end
  119. end
  120. else
  121. filelistUID=filelist;
  122. imagetypeUID=imagetype;
  123. xlocationUID=xlocation;
  124. ylocationUID=ylocation;
  125. zlocationUID=zlocation;
  126. end
  127. % Check for scout images (not AXIAL)
  128. imagetypeAXIAL=' ';
  129. filelistAXIAL=' ';
  130. for i=1:size(filelistUID,1)
  131. if isempty(findstr('AXIAL',imagetypeUID(i,:)))==1 % Scout image found
  132. disp(['The following image :',filelistUID(i,:),' is not AXIAL. Skipped ...']);
  133. change=1; % just make sure we return alterations to the filelist
  134. % added to try read uulke prosate data
  135. counter=counter+1;
  136. imagetypeAXIAL=char(imagetypeAXIAL,imagetypeUID(i,:));
  137. filelistAXIAL=char(filelistAXIAL,filelistUID(i,:));
  138. xlocationAXIAL(counter)=xlocationUID(i);
  139. ylocationAXIAL(counter)=ylocationUID(i);
  140. zlocationAXIAL(counter)=zlocationUID(i);
  141. % added to here
  142. else
  143. counter=counter+1;
  144. imagetypeAXIAL=char(imagetypeAXIAL,imagetypeUID(i,:));
  145. filelistAXIAL=char(filelistAXIAL,filelistUID(i,:));
  146. xlocationAXIAL(counter)=xlocationUID(i);
  147. ylocationAXIAL(counter)=ylocationUID(i);
  148. zlocationAXIAL(counter)=zlocationUID(i);
  149. end
  150. end
  151. if exist('change')~=1
  152. change=0;
  153. end
  154. filelistAXIAL(1,:)=[];
  155. imagetypeAXIAL(1,:)=[];
  156. if change ==1 % export changes to file
  157. newfilename=[filename,'.sort.txt'];
  158. newfile=fopen(newfilename,'w');
  159. for i=1:size(filelistAXIAL,1)
  160. fprintf(newfile,'%c',deblank(filelistAXIAL(i,:))); fprintf(newfile,'\n');
  161. end
  162. disp(['A new file list has been written by dicomrt_loadctlist with name: ',newfilename]);
  163. disp('This file will be used to import ct data instead');
  164. fclose(newfile);
  165. end
  166. % Close progress bar
  167. close(h);
  168. clear info_temp