humaneDVH.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. function humaneDVH(planName245cm,planName0625cm)
  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. %prescTumor = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003linPrescVol\PTV70DosePlus.bin'); %open prescription in Matlab
  7. %prescTumor = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003rootPrescVol\PTV70DosePlus.bin');
  8. prescTumor = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003quadPrescVol\PTV70DosePlus.bin');
  9. %prescTumor = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003gompPrescVol\PTV70DosePlus.bin');
  10. prescNormal = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\NormalDosePlus.bin');
  11. prescLarynx = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\larynxDosePlus.bin');
  12. prescRt = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\RtparotidDosePlus.bin');
  13. prescLt = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\LtparotidDosePlus.bin');
  14. prescCord = open_presc('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input\HN003uniPrescVolNew\CordDosePlus.bin');
  15. %dim = 1; %2D
  16. dim = 30; %3D
  17. fid = fopen(planName245cm,'rb'); %open plans in Matlab
  18. plan245cm = reshape(fread(fid,'float'),72,72,dim);
  19. fclose(fid);
  20. fid = fopen(planName0625cm,'rb'); %open plans in Matlab
  21. plan0625cm = reshape(fread(fid,'float'),72,72,dim);
  22. fclose(fid);
  23. for i=1:prescNormal.Nind;
  24. prescNormal.non_zero_values(i)=1;
  25. end
  26. for i=1:prescLarynx.Nind;
  27. prescLarynx.non_zero_values(i)=1;
  28. end
  29. for i=1:prescRt.Nind;
  30. prescRt.non_zero_values(i)=1;
  31. end
  32. for i=1:prescLt.Nind;
  33. prescLt.non_zero_values(i)=1;
  34. end
  35. for i=1:prescCord.Nind;
  36. prescCord.non_zero_values(i)=1;
  37. end
  38. tumorMask = single(~~(full3D(prescTumor))); %define tissue masks
  39. normalMask = single(~~(full3D(prescNormal)));
  40. larynxMask = single(~~(full3D(prescLarynx)));
  41. rtMask = single(~~(full3D(prescRt)));
  42. ltMask = single(~~(full3D(prescLt)));
  43. cordMask = single(~~(full3D(prescCord)));
  44. tumorDose245cm = plan245cm.*tumorMask; %dose distributions in each ROI
  45. tumorDose0625cm = plan0625cm.*tumorMask;
  46. normalDose245cm = plan245cm.*normalMask;
  47. normalDose0625cm = plan0625cm.*normalMask;
  48. larynxDose245cm = plan245cm.*larynxMask;
  49. larynxDose0625cm = plan0625cm.*larynxMask;
  50. rtDose245cm = plan245cm.*rtMask;
  51. rtDose0625cm = plan0625cm.*rtMask;
  52. ltDose245cm = plan245cm.*ltMask;
  53. ltDose0625cm = plan0625cm.*ltMask;
  54. cordDose245cm = plan245cm.*cordMask;
  55. cordDose0625cm = plan0625cm.*cordMask;
  56. tumorDoseSparse245cm = sparse3D(tumorDose245cm); %convert 3D matrices to sparse matrices
  57. tumorDoseSparse0625cm = sparse3D(tumorDose0625cm);
  58. normalDoseSparse245cm = sparse3D(normalDose245cm);
  59. normalDoseSparse0625cm = sparse3D(normalDose0625cm);
  60. larynxDoseSparse245cm = sparse3D(larynxDose245cm);
  61. larynxDoseSparse0625cm = sparse3D(larynxDose0625cm);
  62. rtDoseSparse245cm = sparse3D(rtDose245cm);
  63. rtDoseSparse0625cm = sparse3D(rtDose0625cm);
  64. ltDoseSparse245cm = sparse3D(ltDose245cm);
  65. ltDoseSparse0625cm = sparse3D(ltDose0625cm);
  66. cordDoseSparse245cm = sparse3D(cordDose245cm);
  67. cordDoseSparse0625cm = sparse3D(cordDose0625cm);
  68. tumorNormDose245cm = ((tumorDoseSparse245cm.non_zero_values)./(prescTumor.non_zero_values)); %calculate equivalent uniform dose
  69. tumorAverageDose245cm = mean(prescTumor.non_zero_values);
  70. tumorEdose245cm = tumorNormDose245cm.*tumorAverageDose245cm;
  71. tumorNormDose0625cm = ((tumorDoseSparse0625cm.non_zero_values)./(prescTumor.non_zero_values)); %calculate equivalent uniform dose
  72. tumorAverageDose0625cm = mean(prescTumor.non_zero_values);
  73. tumorEdose0625cm = tumorNormDose0625cm.*tumorAverageDose245cm;
  74. tumorPrescNorm = ((prescTumor.non_zero_values)./(prescTumor.non_zero_values));
  75. tumorAverageDose = mean(prescTumor.non_zero_values);
  76. tumorPrescEdose = tumorPrescNorm.*tumorAverageDose;
  77. % NON UNIFORM PRESCRIPTIONS TO NORMAL TISSUE AND OAR
  78. % normalNormDose = ((normalDoseSparse.non_zero_values)./(prescNormal.non_zero_values));
  79. % normalAverageDose = mean(normalDoseSparse.non_zero_values);
  80. % normalEdose = normalNormDose.*normalAverageDose;
  81. %
  82. % eyesNormDose = ((eyesDoseSparse.non_zero_values)./(prescEyes.non_zero_values));
  83. % eyesAverageDose = mean(eyesDoseSparse.non_zero_values);
  84. % eyesEdose = eyesNormDose.*eyesAverageDose;
  85. dMax = 1.1*max(tumorEdose245cm);
  86. dvhbins = [0:Ndvhbins-1]*dMax/Ndvhbins;
  87. dHistTumor245cm = histc(tumorEdose245cm,dvhbins);
  88. dHistTumor0625cm = histc(tumorEdose0625cm,dvhbins);
  89. dHistPrescEdose = histc(tumorPrescEdose,dvhbins);
  90. % dHistNormal = histc(normalEdose,dvhbins);
  91. % dHistEyes = histc(eyesEdose,dvhbins);
  92. dHistTumor = histc(tumorDoseSparse245cm.non_zero_values,dvhbins);
  93. dHistTumor2 = histc(tumorDoseSparse0625cm.non_zero_values,dvhbins);
  94. dHistPresc = histc(prescTumor.non_zero_values,dvhbins);
  95. dHistNormal245cm = histc(normalDoseSparse245cm.non_zero_values,dvhbins);
  96. dHistNormal0625cm = histc(normalDoseSparse0625cm.non_zero_values,dvhbins);
  97. dHistLarynx245cm = histc(larynxDoseSparse245cm.non_zero_values,dvhbins);
  98. dHistLarynx0625cm = histc(larynxDoseSparse0625cm.non_zero_values,dvhbins);
  99. dHistRt245cm = histc(rtDoseSparse245cm.non_zero_values,dvhbins);
  100. dHistRt0625cm = histc(rtDoseSparse0625cm.non_zero_values,dvhbins);
  101. dHistLt245cm = histc(ltDoseSparse245cm.non_zero_values,dvhbins);
  102. dHistLt0625cm = histc(ltDoseSparse0625cm.non_zero_values,dvhbins);
  103. dHistCord245cm = histc(cordDoseSparse245cm.non_zero_values,dvhbins);
  104. dHistCord0625cm = histc(cordDoseSparse0625cm.non_zero_values,dvhbins);
  105. dHistTumorNorm245cm = 100*dHistTumor245cm./(double(tumorDoseSparse245cm.Nind));
  106. dHistTumorNorm0625cm = 100*dHistTumor0625cm./(double(tumorDoseSparse0625cm.Nind));
  107. dHistNormalNorm245cm = 100*dHistNormal245cm./(double(normalDoseSparse245cm.Nind));
  108. dHistNormalNorm0625cm = 100*dHistNormal0625cm./(double(normalDoseSparse0625cm.Nind));
  109. dHistLarynxNorm245cm = 100*dHistLarynx245cm./(double(larynxDoseSparse245cm.Nind));
  110. dHistLarynxNorm0625cm = 100*dHistLarynx0625cm./(double(larynxDoseSparse0625cm.Nind));
  111. dHistRtNorm245cm = 100*dHistRt245cm./(double(rtDoseSparse245cm.Nind));
  112. dHistRtNorm0625cm = 100*dHistRt0625cm./(double(rtDoseSparse0625cm.Nind));
  113. dHistLtNorm245cm = 100*dHistLt245cm./(double(ltDoseSparse245cm.Nind));
  114. dHistLtNorm0625cm = 100*dHistLt0625cm./(double(ltDoseSparse0625cm.Nind));
  115. dHistCordNorm245cm = 100*dHistCord245cm./(double(cordDoseSparse245cm.Nind));
  116. dHistCordNorm0625cm = 100*dHistCord0625cm./(double(cordDoseSparse0625cm.Nind));
  117. dHistTumor = 100*dHistTumor/(prescTumor.Nind);
  118. dHistTumor2 = 100*dHistTumor2/(prescTumor.Nind);
  119. dHistPresc = 100*dHistPresc/(prescTumor.Nind);
  120. dHistPrescEdose = 100*dHistPrescEdose/(prescTumor.Nind);
  121. DVHtumor = flipud(cumsum(flipud(dHistTumor)));
  122. DVHtumor2 = flipud(cumsum(flipud(dHistTumor)));
  123. DVHpresc = flipud(cumsum(flipud(dHistPresc)));
  124. DVHprescEdose = flipud(cumsum(flipud(dHistPrescEdose)));
  125. DVHtumor245cm = flipud(cumsum(flipud(dHistTumorNorm245cm)));
  126. DVHtumor0625cm = flipud(cumsum(flipud(dHistTumorNorm0625cm)));
  127. DVHnormal245cm = flipud(cumsum(flipud(dHistNormalNorm245cm)));
  128. DVHnormal0625cm = flipud(cumsum(flipud(dHistNormalNorm0625cm)));
  129. DVHlarynx245cm = flipud(cumsum(flipud(dHistLarynxNorm245cm)));
  130. DVHlarynx0625cm = flipud(cumsum(flipud(dHistLarynxNorm0625cm)));
  131. DVHrt245cm = flipud(cumsum(flipud(dHistRtNorm245cm)));
  132. DVHrt0625cm = flipud(cumsum(flipud(dHistRtNorm0625cm)));
  133. DVHlt245cm = flipud(cumsum(flipud(dHistLtNorm245cm)));
  134. DVHlt0625cm = flipud(cumsum(flipud(dHistLtNorm0625cm)));
  135. DVHcord245cm = flipud(cumsum(flipud(dHistCordNorm245cm)));
  136. DVHcord0625cm = flipud(cumsum(flipud(dHistCordNorm0625cm)));
  137. humanfigure(dvhbins,DVHtumor245cm,DVHtumor0625cm)
  138. %
  139. %DVHnormal245cm,DVHnormal0625cm,DVHlarynx245cm,DVHlarynx0625cm,DVHrt245cm,DVHrt0625cm,DVHlt245cm,DVHlt0625cm,DVHcord245cm,DVHcord0625cm)
  140. end