dvhist.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function [dvh, dosebins] = dvhist(varargin)
  2. % DVHIST Plot a DVH and/or compute the statistics of the plan
  3. %
  4. % Usage:
  5. % [dvh, dosebins, stats] = dvhist (dosemap, contour)
  6. %
  7. % INPUT:
  8. % dosemap = dose distribution, 2D or 3D
  9. % contour = index vector or logical matrix specifying the ROI
  10. % mode = 'relative' (default) or 'absolute'
  11. %
  12. % OUTPUT:
  13. % [] = plot the DVH
  14. % dvh = vector of dvh, ordinate of dvh
  15. % dosebins = dose bin locations, abscissa of the dvh
  16. %
  17. % See also: N/A
  18. %
  19. % TODO: change the way handles displayname or easier to plot output
  20. %
  21. % Copyleft (c) Xiaohu Mo
  22. % Version: 1.3c
  23. if nargin == 2
  24. % (dosemap, contour)
  25. dosemap = varargin{1};
  26. contour = varargin{2};
  27. elseif nargin == 4
  28. % (dosemap, Geometry, ROIindex)
  29. dosemap = varargin{1};
  30. Geometry = varargin{2};
  31. ROIind = varargin{3};
  32. nfraction = varargin{4};
  33. contour = Geometry.ROIS{ROIind}.ind;
  34. else
  35. error('unknown inputs');
  36. end
  37. if isempty(contour)
  38. error('contour is empty');
  39. else
  40. dosevec = dosemap(contour);
  41. end
  42. % calculate DVH
  43. if isempty(find(dosevec, 1))
  44. % if no voxel has dose, hist return -Nbins/2 ~ Nbins/2, affects plotting
  45. dvh = [100 0];
  46. dosebins = [0 1E-3];
  47. else
  48. % Use histogram to calculate DVH
  49. [pdf dosebins] = hist(dosevec, 999);
  50. % clip negative bins
  51. pdf = pdf(dosebins >= 0);
  52. dosebins = dosebins(dosebins >= 0);
  53. dvh = fliplr(cumsum(fliplr(pdf))) / numel(dosevec) * 100;
  54. end
  55. % append the last bin
  56. dosebins = [dosebins dosebins(end)+0.1];
  57. dvh = [dvh 0];
  58. end