normalDVH.asv 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. function normalDVH(uni245cm,lin245cm,root245cm,quad245cm,gomp245cm)
  2. addpath('C:\Documents and Settings\Steve\My Documents\Research\matlab')
  3. addpath('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqUtil')
  4. addpath('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input')
  5. Ndvhbins = 1000; %number of dvh bins
  6. prescTumorUni = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\PTV70dosePlus.bin');
  7. prescTumorLin = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003powerLaw\HN003linPrescVol\PTV70dosePlus.bin'); %open prescription in Matlab
  8. prescTumorRoot = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003powerLaw\normPower2\PTV70dosePlus.bin');
  9. prescTumorQuad = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003powerLaw\HN003quadPrescVol\PTV70dosePlus.bin');
  10. prescTumorGomp = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\sigmoidLaw\HN003gompPrescVol\PTV70dosePlus.bin');
  11. prescNormal = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\NormalDosePlus.bin');
  12. prescLarynx = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\larynxDosePlus.bin');
  13. prescRt = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\RtparotidDosePlus.bin');
  14. prescLt = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\LtparotidDosePlus.bin');
  15. prescCord = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\CordDosePlus.bin');
  16. %dim = 1; %2D
  17. dim = 30; %3D
  18. fid = fopen(uni245cm,'rb'); %open plans in Matlab
  19. planUni245cm = reshape(fread(fid,'float'),72,72,dim);
  20. fclose(fid);
  21. fid = fopen(lin245cm,'rb'); %open plans in Matlab
  22. planLin245cm = reshape(fread(fid,'float'),72,72,dim);
  23. fclose(fid);
  24. fid = fopen(root245cm,'rb'); %open plans in Matlab
  25. planRoot245cm = reshape(fread(fid,'float'),72,72,dim);
  26. fclose(fid);
  27. fid = fopen(quad245cm,'rb'); %open plans in Matlab
  28. planQuad245cm = reshape(fread(fid,'float'),72,72,dim);
  29. fclose(fid);
  30. fid = fopen(gomp245cm,'rb'); %open plans in Matlab
  31. planGomp245cm = reshape(fread(fid,'float'),72,72,dim);
  32. fclose(fid);
  33. for i=1:prescNormal.Nind;
  34. prescNormal.non_zero_values(i)=1;
  35. end
  36. for i=1:prescLarynx.Nind;
  37. prescLarynx.non_zero_values(i)=1;
  38. end
  39. for i=1:prescRt.Nind;
  40. prescRt.non_zero_values(i)=1;
  41. end
  42. for i=1:prescLt.Nind;
  43. prescLt.non_zero_values(i)=1;
  44. end
  45. for i=1:prescCord.Nind;
  46. prescCord.non_zero_values(i)=1;
  47. end
  48. tumorMaskUni = single(~~(full3D(prescTumorUni)));
  49. tumorMaskLin = single(~~(full3D(prescTumorLin))); %define tissue masks
  50. tumorMaskRoot = single(~~(full3D(prescTumorRoot)));
  51. tumorMaskQuad = single(~~(full3D(prescTumorQuad)));
  52. tumorMaskGomp = single(~~(full3D(prescTumorGomp)));
  53. larynxMask = single(~~(full3D(prescLarynx)));
  54. rtMask = single(~~(full3D(prescRt)));
  55. cordMask = single(~~(full3D(prescCord)));
  56. normalMask = single(~~(full3D(prescNormal)));
  57. tumorDoseUni245cm = planUni245cm.*tumorMaskUni;
  58. tumorDoseLin245cm = planLin245cm.*tumorMaskLin; %dose distributions in each ROI
  59. tumorDoseRoot245cm = planRoot245cm.*tumorMaskRoot;
  60. tumorDoseQuad245cm = planQuad245cm.*tumorMaskQuad;
  61. tumorDoseGomp245cm = planGomp245cm.*tumorMaskGomp;
  62. larynxDoseUni245cm = planUni245cm.*larynxMask;
  63. larynxDoseLin245cm = planLin245cm.*larynxMask;
  64. larynxDoseRoot245cm = planRoot245cm.*larynxMask;
  65. larynxDoseQuad245cm = planQuad245cm.*larynxMask;
  66. larynxDoseGomp245cm = planGomp245cm.*larynxMask;
  67. rtDoseUni245cm = planUni245cm.*rtMask;
  68. rtDoseLin245cm = planLin245cm.*rtMask;
  69. rtDoseRoot245cm = planRoot245cm.*rtMask;
  70. rtDoseQuad245cm = planQuad245cm.*rtMask;
  71. rtDoseGomp245cm = planGomp245cm.*rtMask;
  72. cordDoseUni245cm = planUni245cm.*cordMask;
  73. cordDoseLin245cm = planLin245cm.*cordMask;
  74. cordDoseRoot245cm = planRoot245cm.*cordMask;
  75. cordDoseQuad245cm = planQuad245cm.*cordMask;
  76. cordDoseGomp245cm = planGomp245cm.*cordMask;
  77. normalDoseUni245cm = planUni245cm.*normalMask;
  78. normalDoseLin245cm = planLin245cm.*normalMask;
  79. normalDoseRoot245cm = planRoot245cm.*normalMask;
  80. normalDoseQuad245cm = planQuad245cm.*normalMask;
  81. normalDoseGomp245cm = planGomp245cm.*normalMask;
  82. tumorDoseSparseUni245cm = sparse3D(tumorDoseUni245cm); %convert 3D matrices to sparse matrices
  83. tumorDoseSparseLin245cm = sparse3D(tumorDoseLin245cm);
  84. tumorDoseSparseRoot245cm = sparse3D(tumorDoseRoot245cm);
  85. tumorDoseSparseQuad245cm = sparse3D(tumorDoseQuad245cm);
  86. tumorDoseSparseGomp245cm = sparse3D(tumorDoseGomp245cm);
  87. larynxDoseSparseUni245cm = sparse3D(larynxDoseUni245cm);
  88. larynxDoseSparseLin245cm = sparse3D(larynxDoseLin245cm);
  89. larynxDoseSparseRoot245cm = sparse3D(larynxDoseRoot245cm);
  90. larynxDoseSparseQuad245cm = sparse3D(larynxDoseQuad245cm);
  91. larynxDoseSparseGomp245cm = sparse3D(larynxDoseGomp245cm);
  92. rtDoseSparseUni245cm = sparse3D(rtDoseUni245cm);
  93. rtDoseSparseLin245cm = sparse3D(rtDoseLin245cm);
  94. rtDoseSparseRoot245cm = sparse3D(rtDoseRoot245cm);
  95. rtDoseSparseQuad245cm = sparse3D(rtDoseQuad245cm);
  96. rtDoseSparseGomp245cm = sparse3D(rtDoseGomp245cm);
  97. cordDoseSparseUni245cm = sparse3D(cordDoseUni245cm);
  98. cordDoseSparseLin245cm = sparse3D(cordDoseLin245cm);
  99. cordDoseSparseRoot245cm = sparse3D(cordDoseRoot245cm);
  100. cordDoseSparseQuad245cm = sparse3D(cordDoseQuad245cm);
  101. cordDoseSparseGomp245cm = sparse3D(cordDoseGomp245cm);
  102. normalDoseSparseUni245cm = sparse3D(normalDoseUni245cm);
  103. normalDoseSparseLin245cm = sparse3D(normalDoseLin245cm);
  104. normalDoseSparseRoot245cm = sparse3D(normalDoseRoot245cm);
  105. normalDoseSparseQuad245cm = sparse3D(normalDoseQuad245cm);
  106. normalDoseSparseGomp245cm = sparse3D(normalDoseGomp245cm);
  107. tumorNormDoseLin245cm = ((tumorDoseSparseLin245cm.non_zero_values)./(prescTumorLin.non_zero_values)); %calculate equivalent uniform dose
  108. tumorAverageDoseLin245cm = mean(prescTumorLin.non_zero_values);
  109. tumorEdoseLin245cm = tumorNormDoseLin245cm.*tumorAverageDoseLin245cm;
  110. % tumorEdoseLin245cm = tumorNormDoseLin245cm;
  111. % indLin = find(((tumorNormDoseLin245cm-1.).^2).^(1/2) >= 0.05);
  112. % volLin = 100.-double(length(indLin))./(double(tumorDoseSparseLin245cm.Nind))*100
  113. tumorNormDoseRoot245cm = ((tumorDoseSparseRoot245cm.non_zero_values)./(prescTumorRoot.non_zero_values)); %calculate equivalent uniform dose
  114. tumorAverageDoseRoot245cm = mean(prescTumorRoot.non_zero_values);
  115. tumorEdoseRoot245cm = tumorNormDoseRoot245cm.*tumorAverageDoseRoot245cm;
  116. % tumorEdoseRoot245cm = tumorNormDoseRoot245cm;
  117. % indRoot = find(((tumorNormDoseRoot245cm-1.).^2).^(1/2) >= 0.05);
  118. % volRoot = 100.-double(length(indRoot))./(double(tumorDoseSparseRoot245cm.Nind))*100
  119. tumorNormDoseQuad245cm = ((tumorDoseSparseQuad245cm.non_zero_values)./(prescTumorQuad.non_zero_values)); %calculate equivalent uniform dose
  120. tumorAverageDoseQuad245cm = mean(prescTumorQuad.non_zero_values);
  121. tumorEdoseQuad245cm = tumorNormDoseQuad245cm.*tumorAverageDoseQuad245cm;
  122. % tumorEdoseQuad245cm = tumorNormDoseQuad245cm;
  123. % indQuad = find(((tumorNormDoseQuad245cm-1.).^2).^(1/2) >= 0.05);
  124. % volQuad = 100.-double(length(indQuad))./(double(tumorDoseSparseQuad245cm.Nind))*100
  125. tumorNormDoseGomp245cm = ((tumorDoseSparseGomp245cm.non_zero_values)./(prescTumorGomp.non_zero_values)); %calculate equivalent uniform dose
  126. tumorAverageDoseGomp245cm = mean(prescTumorGomp.non_zero_values);
  127. tumorEdoseGomp245cm = tumorNormDoseGomp245cm.*tumorAverageDoseGomp245cm;
  128. dMax = 1.1*max(tumorEdoseLin245cm);
  129. dvhbins = [0:Ndvhbins-1]*dMax./Ndvhbins;
  130. dHistTumorLin245cm = histc(tumorEdoseLin245cm,dvhbins);
  131. dHistTumorRoot245cm = histc(tumorEdoseRoot245cm,dvhbins);
  132. dHistTumorQuad245cm = histc(tumorEdoseQuad245cm,dvhbins);
  133. dHistTumorGomp245cm = histc(tumorEdoseGomp245cm,dvhbins);
  134. dHistTumorUni245cm = histc(tumorDoseSparseUni245cm.non_zero_values,dvhbins);
  135. dHistTumorLin = histc(tumorDoseSparseLin245cm.non_zero_values,dvhbins);
  136. dHistTumorRoot = histc(tumorDoseSparseRoot245cm.non_zero_values,dvhbins);
  137. dHistTumorQuad = histc(tumorDoseSparseQuad245cm.non_zero_values,dvhbins);
  138. dHistTumorGomp = histc(tumorDoseSparseGomp245cm.non_zero_values,dvhbins);
  139. dHistLarynxUni245cm = histc(larynxDoseSparseUni245cm.non_zero_values,dvhbins);
  140. dHistLarynxLin245cm = histc(larynxDoseSparseLin245cm.non_zero_values,dvhbins);
  141. dHistLarynxRoot245cm = histc(larynxDoseSparseRoot245cm.non_zero_values,dvhbins);
  142. dHistLarynxQuad245cm = histc(larynxDoseSparseQuad245cm.non_zero_values,dvhbins);
  143. dHistLarynxGomp245cm = histc(larynxDoseSparseGomp245cm.non_zero_values,dvhbins);
  144. dHistRtUni245cm = histc(rtDoseSparseUni245cm.non_zero_values,dvhbins);
  145. dHistRtLin245cm = histc(rtDoseSparseLin245cm.non_zero_values,dvhbins);
  146. dHistRtRoot245cm = histc(rtDoseSparseRoot245cm.non_zero_values,dvhbins);
  147. dHistRtQuad245cm = histc(rtDoseSparseQuad245cm.non_zero_values,dvhbins);
  148. dHistRtGomp245cm = histc(rtDoseSparseGomp245cm.non_zero_values,dvhbins);
  149. dHistCordUni245cm = histc(cordDoseSparseUni245cm.non_zero_values,dvhbins);
  150. dHistCordLin245cm = histc(cordDoseSparseLin245cm.non_zero_values,dvhbins);
  151. dHistCordRoot245cm = histc(cordDoseSparseRoot245cm.non_zero_values,dvhbins);
  152. dHistCordQuad245cm = histc(cordDoseSparseQuad245cm.non_zero_values,dvhbins);
  153. dHistCordGomp245cm = histc(cordDoseSparseGomp245cm.non_zero_values,dvhbins);
  154. dHistNormalUni245cm = histc(normalDoseSparseUni245cm.non_zero_values,dvhbins);
  155. dHistNormalLin245cm = histc(normalDoseSparseLin245cm.non_zero_values,dvhbins);
  156. dHistNormalRoot245cm = histc(normalDoseSparseRoot245cm.non_zero_values,dvhbins);
  157. dHistNormalQuad245cm = histc(normalDoseSparseQuad245cm.non_zero_values,dvhbins);
  158. dHistNormalGomp245cm = histc(normalDoseSparseGomp245cm.non_zero_values,dvhbins);
  159. dHistTumorNormUni245cm = 100*dHistTumorUni245cm./(double(tumorDoseSparseUni245cm.Nind));
  160. dHistTumorNormLin245cm = 100*dHistTumorLin245cm./(double(tumorDoseSparseLin245cm.Nind));
  161. dHistTumorNormRoot245cm = 100*dHistTumorRoot245cm./(double(tumorDoseSparseRoot245cm.Nind));
  162. dHistTumorNormQuad245cm = 100*dHistTumorQuad245cm./(double(tumorDoseSparseQuad245cm.Nind));
  163. dHistTumorNormGomp245cm = 100*dHistTumorGomp245cm./(double(tumorDoseSparseGomp245cm.Nind));
  164. dHistTumorNormLin = 100*dHistTumorLin./(double(tumorDoseSparseLin245cm.Nind));
  165. dHistTumorNormRoot = 100*dHistTumorRoot./(double(tumorDoseSparseRoot245cm.Nind));
  166. dHistTumorNormQuad = 100*dHistTumorQuad./(double(tumorDoseSparseQuad245cm.Nind));
  167. dHistTumorNormGomp = 100*dHistTumorGomp/(prescTumorGomp.Nind);
  168. dHistLarynxNormUni245cm = 100*dHistLarynxUni245cm./(double(larynxDoseSparseUni245cm.Nind));
  169. dHistLarynxNormLin245cm = 100*dHistLarynxLin245cm./(double(larynxDoseSparseLin245cm.Nind));
  170. dHistLarynxNormRoot245cm = 100*dHistLarynxRoot245cm./(double(larynxDoseSparseRoot245cm.Nind));
  171. dHistLarynxNormQuad245cm = 100*dHistLarynxQuad245cm./(double(larynxDoseSparseQuad245cm.Nind));
  172. dHistLarynxNormGomp245cm = 100*dHistLarynxGomp245cm./(double(larynxDoseSparseGomp245cm.Nind));
  173. dHistRtNormUni245cm = 100*dHistRtUni245cm./(double(rtDoseSparseUni245cm.Nind));
  174. dHistRtNormLin245cm = 100*dHistRtLin245cm./(double(rtDoseSparseLin245cm.Nind));
  175. dHistRtNormRoot245cm = 100*dHistRtRoot245cm./(double(rtDoseSparseRoot245cm.Nind));
  176. dHistRtNormQuad245cm = 100*dHistRtQuad245cm./(double(rtDoseSparseQuad245cm.Nind));
  177. dHistRtNormGomp245cm = 100*dHistRtGomp245cm./(double(rtDoseSparseGomp245cm.Nind));
  178. dHistCordNormUni245cm = 100*dHistCordUni245cm./(double(cordDoseSparseUni245cm.Nind));
  179. dHistCordNormLin245cm = 100*dHistCordLin245cm./(double(cordDoseSparseLin245cm.Nind));
  180. dHistCordNormRoot245cm = 100*dHistCordRoot245cm./(double(cordDoseSparseRoot245cm.Nind));
  181. dHistCordNormQuad245cm = 100*dHistCordQuad245cm./(double(cordDoseSparseQuad245cm.Nind));
  182. dHistCordNormGomp245cm = 100*dHistCordGomp245cm./(double(cordDoseSparseGomp245cm.Nind));
  183. dHistNormalNormUni245cm = 100*dHistNormalUni245cm./(double(normalDoseSparseUni245cm.Nind));
  184. dHistNormalNormLin245cm = 100*dHistNormalLin245cm./(double(normalDoseSparseLin245cm.Nind));
  185. dHistNormalNormRoot245cm = 100*dHistNormalRoot245cm./(double(normalDoseSparseRoot245cm.Nind));
  186. dHistNormalNormQuad245cm = 100*dHistNormalQuad245cm./(double(normalDoseSparseQuad245cm.Nind));
  187. dHistNormalNormGomp245cm = 100*dHistNormalGomp245cm./(double(normalDoseSparseGomp245cm.Nind));
  188. DVHtumorUni245cm = flipud(cumsum(flipud(dHistTumorNormUni245cm)));
  189. DVHtumorLin245cm = flipud(cumsum(flipud(dHistTumorNormLin245cm)));
  190. DVHtumorRoot245cm = flipud(cumsum(flipud(dHistTumorNormRoot245cm)));
  191. DVHtumorQuad245cm = flipud(cumsum(flipud(dHistTumorNormQuad245cm)));
  192. DVHtumorGomp245cm = flipud(cumsum(flipud(dHistTumorNormGomp245cm)));
  193. DVHtumorLin = flipud(cumsum(flipud(dHistTumorNormLin)));
  194. DVHtumorRoot = flipud(cumsum(flipud(dHistTumorNormRoot)));
  195. DVHtumorQuad = flipud(cumsum(flipud(dHistTumorNormQuad)));
  196. DVHtumorGomp = flipud(cumsum(flipud(dHistTumorNormGomp)));
  197. DVHlarynxUni245cm = flipud(cumsum(flipud(dHistLarynxNormUni245cm)));
  198. DVHlarynxLin245cm = flipud(cumsum(flipud(dHistLarynxNormLin245cm)));
  199. DVHlarynxRoot245cm = flipud(cumsum(flipud(dHistLarynxNormRoot245cm)));
  200. DVHlarynxQuad245cm = flipud(cumsum(flipud(dHistLarynxNormQuad245cm)));
  201. DVHlarynxGomp245cm = flipud(cumsum(flipud(dHistLarynxNormGomp245cm)));
  202. DVHrtUni245cm = flipud(cumsum(flipud(dHistRtNormUni245cm)));
  203. DVHrtLin245cm = flipud(cumsum(flipud(dHistRtNormLin245cm)));
  204. DVHrtRoot245cm = flipud(cumsum(flipud(dHistRtNormRoot245cm)));
  205. DVHrtQuad245cm = flipud(cumsum(flipud(dHistRtNormQuad245cm)));
  206. DVHrtGomp245cm = flipud(cumsum(flipud(dHistRtNormGomp245cm)));
  207. DVHcordUni245cm = flipud(cumsum(flipud(dHistCordNormUni245cm)));
  208. DVHcordLin245cm = flipud(cumsum(flipud(dHistCordNormLin245cm)));
  209. DVHcordRoot245cm = flipud(cumsum(flipud(dHistCordNormRoot245cm)));
  210. DVHcordQuad245cm = flipud(cumsum(flipud(dHistCordNormQuad245cm)));
  211. DVHcordGomp245cm = flipud(cumsum(flipud(dHistCordNormGomp245cm)));
  212. DVHnormalUni245cm = flipud(cumsum(flipud(dHistNormalNormUni245cm)));
  213. DVHnormalLin245cm = flipud(cumsum(flipud(dHistNormalNormLin245cm)));
  214. DVHnormalRoot245cm = flipud(cumsum(flipud(dHistNormalNormRoot245cm)));
  215. DVHnormalQuad245cm = flipud(cumsum(flipud(dHistNormalNormQuad245cm)));
  216. DVHnormalGomp245cm = flipud(cumsum(flipud(dHistNormalNormGomp245cm)));
  217. figNormal(dvhbins,DVHrtLin245cm,DVHrtRoot245cm,DVHrtQuad245cm,...
  218. DVHcordLin245cm,DVHcordRoot245cm,DVHcordQuad245cm,...
  219. DVHlarynxLin245cm,DVHlarynxRoot245cm,DVHlarynxQuad245cm,...
  220. DVHnormalLin245cm,DVHnormalRoot245cm,DVHnormalQuad245cm)
  221. end