merge_beamlets.m 1.0 KB

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