dvh.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function DVH = dvh(dose,mask,d_bins)
  2. % A dose volume histogram is calculated for a region of interest (roi)
  3. % using dose bins specified by the user.
  4. %
  5. % Inputs: dose = dose distribution
  6. % mask = mask of zeros and ones that specifies the roi
  7. % d_bins = dose bin boundaries, must be a vector
  8. %
  9. % Output: d_hist = dose volume histogram defined as:
  10. % d_hist(j) = percentage of voxels in the region of interested
  11. % receiving a dose of d_bins(j) or greater.
  12. % ensure that d_bins is a vector
  13. if prod(size(d_bins)) > length(d_bins)
  14. error('Third input argument must be a vector.');
  15. end
  16. % ensure that the mask is just ones and zeros
  17. if ~isempty(find(mask~=0 & mask~=1))
  18. error('Mask must consist of zeros and ones only.');
  19. end
  20. % ensure that the mask and the dose matrix are the same size
  21. if size(dose,1) ~= size(mask,1) | size(dose,2) ~= size(mask,2) ...
  22. | size(dose,3) ~= size(mask,3)
  23. error('The dose matrix and the mask must be the same size.');
  24. end
  25. Nbins = length(d_bins); % number of bins in the dvh
  26. Nvoxels = sum(mask(:)); % number of voxels in the mask
  27. d_hist = zeros(1,length(d_bins));
  28. DVH = zeros(size(d_hist));
  29. ind = find(mask == 1); % indices that lie in the roi
  30. if ~isempty(ind)
  31. dose_vector = dose(ind); % vector of dose
  32. d_hist = histc(dose(ind),d_bins); % create the differential histogram
  33. d_hist = 100*d_hist/length(ind); % renomalize
  34. DVH = flipud(cumsum(flipud(d_hist)));
  35. end