Skip to content

Instantly share code, notes, and snippets.

@ofgulban
Created April 24, 2021 15:14
Show Gist options
  • Save ofgulban/4e5b02ce650550c8cfc2b3a1cd2c403c to your computer and use it in GitHub Desktop.
Save ofgulban/4e5b02ce650550c8cfc2b3a1cd2c403c to your computer and use it in GitHub Desktop.
Convert BrainVoyager reions of interests in volume (VOI) to .vmr files
% Convert BrainVoyager reions of interests in volume (VOI) to .vmr files
%
% Similar to draw VOI in VMR option in BV but assigns unique numbers for
% each voi.
clear all
vmr_file = '/path/to/file.vmr';
voi_file = '/path/to/file.voi';
out_dir = '/path/to/ourdir';
vmr = xff(vmr_file);
voi = xff(voi_file);
[path, filename, ext] = fileparts(voi_file);
selected_VOIs = [2 3 4 5 6 7 8 9 10];
c_s = 2; % closing_steps
temp = vmr.copyobject;
temp.VMRData = zeros(size(temp.VMRData));
for i = selected_VOIs
temp_data = zeros(size(temp.VMRData));
temp_data(sub2ind(size(temp_data), ...
voi.VOI(i).Voxels(:,1)+1, ...
voi.VOI(i).Voxels(:,2)+1, ...
voi.VOI(i).Voxels(:,3)+1)) = 225 + i;
% (optional) dilate, erode
temp_data = imdilate(temp_data, ones(c_s, c_s, c_s));
temp_data = imerode(temp_data, ones(c_s, c_s, c_s));
% put the processed voi as a unique number inside VMR
temp.VMRData(temp_data>0) = temp_data(temp_data>0);
disp(['VOI ' num2str(i) ' (' voi.VOI(i).Name ') is done.'])
end
temp.SaveAs(fullfile(out_dir, [filename '_vois.vmr']));
disp('Finished.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment