1
0

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