QVH.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. addpath('C:\Documents and Settings\Steve\My Documents\Research\matlab')
  2. addpath('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqUtil')
  3. addpath('C:\Documents and Settings\Steve\My Documents\Research\optNew\linlsqOpt\input')
  4. prescFile = 'presc.img'; %locate prescription and plan filenames
  5. planFile1 = 'plan1.img';
  6. planFile2 = 'plan2.img';
  7. planFile3 = 'plan3.img';
  8. dim1 = 512;
  9. dim2 = dim1;
  10. dim3 = 35; %3D matrix dimensions
  11. fid = fopen(prescFile,'rb'); %open plans in Matlab
  12. presc = reshape(fread(fid,'float'),dim1,dim2,dim3);
  13. fclose(fid);
  14. fid = fopen(planFile1,'rb'); %open plans in Matlab
  15. plan1 = reshape(fread(fid,'float'),dim1,dim2,dim3);
  16. fclose(fid);
  17. fid = fopen(planFile2,'rb'); %open plans in Matlab
  18. plan2 = reshape(fread(fid,'float'),dim1,dim2,dim3);
  19. fclose(fid);
  20. fid = fopen(prescFile3,'rb'); %open plans in Matlab
  21. plan3 = reshape(fread(fid,'float'),dim1,dim2,dim3);
  22. fclose(fid);
  23. PTVmask = single(~~(presc)); %define tissue mask
  24. PTVdose1 = plan1.*tumorMask; %dose distributions in each ROI
  25. PTVdose2 = plan2.*tumorMask; %dose distributions in each ROI
  26. PTVdose3 = plan3.*tumorMask; %dose distributions in each ROI
  27. PTVdoseSparse1 = sparse3D(PTVdose1);
  28. PTVdoseSparse2 = sparse3D(PTVdose2);
  29. PTVdoseSparse3 = sparse3D(PTVdose3);
  30. PTVnormDose1 = ((PTVdoseSparse1.non_zero_values)./(PTVpresc.non_zero_values)); %calculate normalized dose
  31. ind1 = find(((PTVnormDose1-1.).^2).^(1/2) >= 0.05); %find voxels whose plans deviate from prescription > 5 percent
  32. vol1 = 100.-double(length(ind1))./(double(PTVnormDose1.Nind))*100; %calculate PTV percentage whose plan is within 5 percent prescription
  33. PTVnormDose2 = ((PTVdoseSparse2.non_zero_values)./(PTVpresc.non_zero_values));
  34. ind2 = find(((PTVnormDose2-1.).^2).^(1/2) >= 0.05);
  35. vol2 = 100.-double(length(ind2))./(double(PTVnormDose2.Nind))*100;
  36. PTVnormDose3 = ((PTVdoseSparse3.non_zero_values)./(PTVpresc.non_zero_values));
  37. ind3 = find(((PTVnormDose3-1.).^2).^(1/2) >= 0.05);
  38. vol3 = 100.-double(length(ind3))./(double(PTVnormDose3.Nind))*100;
  39. Ndvhbins = 1000; %number of dvh bins
  40. dMax = 1.1*max(PTVnormDose1); %define maximum bin for QVH
  41. dvhbins = [0:Ndvhbins-1]*dMax/Ndvhbins; %define bins
  42. dHistPTVnormDose1 = histc(PTVnormDose1,dvhbins); %bin normalized PTV dose
  43. dHistPTVnormDose1 = 100*dHistPTVnormDose1./(double(PTVnormDose1.Nind)); %calculate frequency percentage of integral
  44. dHistPTVnormDose2 = histc(PTVnormDose2,dvhbins); %bin normalized PTV dose
  45. dHistPTVnormDose2 = 100*dHistPTVnormDose2./(double(PTVnormDose2.Nind)); %calculate frequency percentage of integral
  46. dHistPTVnormDose3 = histc(PTVnormDose3,dvhbins); %bin normalized PTV dose
  47. dHistPTVnormDose3 = 100*dHistPTVnormDose3./(double(PTVnormDose3.Nind)); %calculate frequency percentage of integral
  48. QVHptv1 = flipud(cumsum(flipud(dHistPTVnormDose1))); %cumulatively sum histogram from max min to min bin
  49. QVHptv2 = flipud(cumsum(flipud(dHistPTVnormDose2))); %cumulatively sum histogram from max min to min bin
  50. QVHptv3 = flipud(cumsum(flipud(dHistPTVnormDose3))); %cumulatively sum histogram from max min to min bin
  51. plotQVH(dvhbins,QVHptv1, QVHptv2, QVHptv3) %plot QVH