Hi Mark,
Thank you for replying.
I've tried to do it as you suggested, but ran into a problem (sorry if this is just a trivial issue, I'm not so good with matlab).
Here is the code from the matlab window with the error after the last line:
>> [im,dims,scales]=read_avw('test_dwi_indexed+1+116_masked.nii.gz');
>> vals=load('connectivity_index_noconnectionseq0.txt');
>> vals1=[0; vals];
>> im1=vals1(im+1);
Index exceeds matrix dimensions.
My text file is a column vector.
What does the line im1=vals1(im+1) do?
best,
Georg
On Jul 23, 2015, at 5:28 PM, Mark Jenkinson wrote:
> Hi,
>
> I don’t think there is a way of doing this with existing FSL tools. However, the following matlab/octave code will do it easily:
>
> [im,dims,scales]=read_avw(‘imagename’);
> vals=load(‘textfilename’);
> vals1=[0; vals]; % change this to [0 vals] if your values are a row vector
> im1=vals1(im+1);
> save_avw(im1,’newimagename’,’f',scales);
>
> then, outside of matlab/octave, do:
>
> fslcpgeom imagename newimagename
>
> This final command will restore all the correct label/coordinate information that gets lost in the matlab/octave reading.
>
> All the best,
> Mark
>
>
> From: FSL - FMRIB's Software Library <[log in to unmask]> on behalf of Georg Kerbler <[log in to unmask]>
> Reply-To: FSL - FMRIB's Software Library <[log in to unmask]>
> Date: Thursday, 23 July 2015 02:16
> To: "[log in to unmask]" <[log in to unmask]>
> Subject: [FSL] Replace voxel values within an ROI with values from a text-file
>
> Hello all,
>
> I have an ROI which is 2933 voxels big and every voxel has a unique index number (created with fslmaths -index starting from a binary ROI).
> I also shifted the index numbers by +117 in order to combine it with another ROI (AAL atlas) so the index numbers end up being 117-3049 in the ROI which I want to change the values of.
>
> Now the actual goal is to replace the numbers 117-3049 in my ROI (masked nifti image) with numbers from a text file where each value (a single integer) in each row from 1-2933 corresponds to the 117-3049 voxels in the image.
> So, e.g. the text file looks like this:
>
> 21
> 21
> 33
> 45
> 0
> 0
> 5
> …. etc.
>
> I want to replace voxels indexed with 117-118 with 21, voxel 119 with 33, voxel 120 with 45, voxel 121-122 with 0 etc.
> (Just to give it some context, my text file represents the cortical areas that each voxel is most connected to measured through number of streamlines by tractography; the 0's mean that this voxel did not show any connectivity with any region).
>
> Thanks for your input,
> Georg
|