function MakeSeedpoints(seedmask_name,seedpoints_name,seedpoints_idx_name,ds_factor) % ----------------- USAGE ----------------- % run this in the muscle folder via terminal/commandline % in muscle folder, should be segmentations folder % ----------------- ARGUMENTS ----------------- % seedmask_name: string of desired seedmask .nii file and path(EX: 'muscle_seedmask.nii.gz') % seedpoints_name: string of desired seedpoints .txt file and path (EX: 'muscle_seedpoints.txt') % seedpoints_idx_name: string of desired seedpoints .txt file and path (EX: 'muscle_seedpoints_idx.txt') % ds_factor: how much to downsample the seedmask voxels by (EX: 2) % ----------------- OUTPUTS ---------------- % seedpoints_name: a .txt file to be imported into FSL for tractography (EX: 'muscle_seedpoints.txt') % seedpoints_name_idx: a .txt file to be imported into FSL for tractography (EX: 'muscle_seedpoints_idx.txt') %% Extract Voxel Coordinates from Seed Mask fprintf('Creating array of all non-zero voxels in given seedmask: %s...\n',seedmask_name); % Load NIFTI Images seed_img = load_untouch_nii(seedmask_name); % Load the seed mask as a NIFTI structure seedmask = seed_img.img; % Get the image from the structure % Find Coordinates idx = find(seedmask); % Find linear indices of all NON-ZERO intensity values [row, col, slice] = ind2sub(size(seedmask),idx); % Separate indices to subscripts to find x,y,z fibnr = find(row(:)); % Find the index number for the coordinate seedpoints = [fibnr(:), row(:), col(:), slice(:)]; % Create4 an Nx4 matrix with coordinates of all voxels in seedmask (n,x,y,z) %% Save Seedpoint Text Files % Downsample the Seedpoints by Given Factor seedpoints_ds = downsample(seedpoints,ds_factor); % Downsample the seedpoints by factor - don't need contiguous voxels seedpoints_ds_no_idx = seedpoints_ds(:,2:4); % Same downsampling for file without indices % Save Seedpoints File with No Index writematrix(seedpoints_ds_no_idx,seedpoints_name,'Delimiter','space'); % save as .txt file to import into FSL commands % N = number of rows = total number of voxels the mask contains % x = column 1 = x-coordinates in diffusion MRI space % y = column 2 = y-coordinates in diffusion MRI space % z = column 3 = z-coordinates in diffusion MRI space fprintf('Seedpoint array saved as %s\n',seedpoints_name); % Save Seedpoints File with Index seedpoints_ds_idx = seedpoints_ds; j = find(seedpoints_ds(:,1)); seedpoints_ds_idx(:,1) = j; writematrix(seedpoints_ds_idx,seedpoints_idx_name,'Delimiter','space'); % save as .txt file to import into FSL commands % N = number of rows = total number of voxels the mask contains % n = column 1 = seedpoint/fiber number % x = column 2 = x-coordinates in diffusion MRI space % y = column 3 = y-coordinates in diffusion MRI space % z = column 4 = z-coordinates in diffusion MRI space fprintf('Seedpoint indexed array saved as %s\n',seedpoints_idx_name); exit; end