merge_beamlets.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. function B = merge_beamlets(num_batches, pat_dir)
  2. % num_batches = 4;
  3. B = [];
  4. for k = 1:num_batches
  5. batch_doses = read_ryan_beamlets([pat_dir, '\batch_dose' num2str(k-1) '.bin']);
  6. B = [B batch_doses];
  7. end
  8. write_ryan_beamlets([pat_dir '\batch_dose_unshifted.bin'],B);
  9. % apply the shift (0.5 vox up and left) to make dose match geometry
  10. f = waitbar(0, 'Correcting beamlet shift');
  11. for beam_i = 1:numel(B)
  12. new_dose_list = B{beam_i};
  13. waitbar(beam_i/numel(B),f, ['Correcting beamlet shift: ' num2str(beam_i)])
  14. tabula = zeros(B{1, beam_i}.y_count, B{1, beam_i}.x_count, B{1, beam_i}.z_count);
  15. tabula(B{1, beam_i}.non_zero_indices) = B{1, beam_i}.non_zero_values;
  16. shifted_img = imtranslate(tabula, [-0.5,-0.5,-0.5]);
  17. nonzero_idx = find(shifted_img>0.005*max(shifted_img(:)));
  18. B{beam_i}.non_zero_indices = nonzero_idx;
  19. B{beam_i}.non_zero_values = shifted_img(nonzero_idx);
  20. end
  21. close(f)
  22. for k = 1:numel(B)
  23. B{k}.num = k-1;
  24. end
  25. write_ryan_beamlets([pat_dir '\batch_dose.bin'],B);
  26. write_ryan_beamlets([pat_dir '\batch_dose_backup.bin'],B);