For anyone reading this or searching for help on fslascii2img but still confused, for me I got this to work using a 1D vector (1 column of intensity values). Previously I had a 4D matrix (x, y, z, intensity value). The function didn’t seem to understand that I wanted the 4th column to be intensity values while the first 3 columns represented coordinates. Perhaps I was misusing the arguments. Nevertheless, so long as your column is sorted in the following order (z=0 to n, then y=0 to n, then x=0 to n) then the function will work with the following call (assuming you only have 1 volume to write, for me it’s just a map of correlation values for every voxel in the MNI 2mm brain):

fslascii2img YourTextFile.txt 91 109 91 1 2 2 2 0 YourImage.nii.gz

The MNI 2mm brain in voxels goes from 0 to 90 for z and x, hence the 91’s, and it goes from 0 to 108 for y, hence the 109. The 2 2 2 tells it there are 2 millimeters in between each x, y, and z slice respectively. I used 0 for TR because this isn’t fmri data, isn’t multiple volumes, and it worked when I tried it. 

Keep in mind again that I only know this to work for my data (1 volume, vector of r-values for each voxel of the MNI 2mm brain). But if your data is similar, you should be able to adapt the arguments.

-Ben

Ben Chernoff
Ph.D. Student, Concepts, Actions, and Objects Lab
Rochester Center for Brain Imaging, Room 2B231
University of Rochester

On Jul 7, 2017, at 8:23 AM, Matthew Webster <[log in to unmask]> wrote:

Hello Ben,
 You will need to create a script that iterates over the voxel co-ordinates of the target image ( in order starting with 0,0,0) and writes either a 0, or a value from your input file, to another text file. A simpler option might be ( if you are familiar with python ) to write a python script that creates a blank image of the desired size and then loops over your text file to fill in those specific values.

Kind Regards
Matthew
--------------------------------
Dr Matthew Webster
FMRIB Centre 
John Radcliffe Hospital
University of Oxford

On 7 Jul 2017, at 12:31, Chernoff, Ben <[log in to unmask]> wrote:

Hi Dr Wester,

That makes sense. Right now I simple have an nx4 file where n is the number of voxels in the brain (something like 500,000) and the columns are x, y, z, and intensity value. Based on Dr. Bergsland’s example below I would need to have a set of 9 numbers (intensity value surrounded by 0’s) for every single coordinate? Or is there an easier way to convert the list I have into “full text image” like you said?

Thanks!

-Ben

Ben Chernoff
Ph.D. Student, Concepts, Actions, and Objects Lab
Rochester Center for Brain Imaging, Room 2B231
University of Rochester

On Jul 7, 2017, at 6:47 AM, Matthew Webster <[log in to unmask]> wrote:

Hello,
 To confirm fslascii2img takes a full sequence of numbers ( assumed to be in the NIFTI storage order ) and creates a NIFTI file from them. If you have a list of co-ordinates, you will need to convert these to a “full text image” first.

Hope this helps,
Matthew
--------------------------------
Dr Matthew Webster
FMRIB Centre 
John Radcliffe Hospital
University of Oxford

On 7 Jul 2017, at 08:34, Niels Bergsland <[log in to unmask]> wrote:

Hi Ben,
Here is a simple toy example that should hopefully get you going:

> cat test.txt

0 0 0
0 1 0
0 0 0

0 0 0
0 2 0
0 0 0

0 0 0
0 3 0
0 0 0

This corresponds to a 3x3x3 image where the middle voxel on the first slice equals 1 (surrounded by zeros), middle voxel equals 2 on the second slice and middle voxel equals 3 on the third slice.

Converting this to an image with 1mm isotropic voxels:
> fslascii2img test.txt 3 3 3 1 1 1 1 1 image

Sanity check:
> fslinfo image
dim1           3
dim2           3
dim3           3
dim4           1
datatype       16
pixdim1        1.000000
pixdim2        1.000000
pixdim3        1.000000
pixdim4        1.000000

Opening in an image viewer also confirms that the resulting image is as expected.

Let me know if you get stuck or have other questions,
Niels





On Thu, Jul 6, 2017 at 10:48 PM, Chernoff, Ben <[log in to unmask]> wrote:
>
> Dr. Bergsland,
>
> Thank you very much for the reply. I suspected fslascii2img would make sense but the documentation is extremely sparse and I’ve failed in my attempts to experiment with it. Zero’s for all other coordinates is no problem, I have that by default anyway because of fslmeants --showall. However, if fslascii2img takes the text file as input and the text file already has every single coordinate (x, y, z) and intensity value as well, what do I use for the arguments of fslascii2img?
>
> Thank you!
>
> -Ben
>
> Ben Chernoff
> Ph.D. Student, Concepts, Actions, and Objects Lab
> Rochester Center for Brain Imaging, Room 2B231
> University of Rochester
>
> On Jul 6, 2017, at 3:22 PM, Niels Bergsland <[log in to unmask]> wrote:
>
> Re-reading your email, you'll need to get the original text file with your coordinates into a format such that there are zeros in all other coordinates. But that shouldn't be too difficult, and will certainly more efficient.
>
> On Thu, Jul 6, 2017 at 21:17 Niels Bergsland <[log in to unmask]> wrote:
>>
>> Hi there,,
>> It sounds like fslascii2img should do the trick for you.
>>
>> On Thu, Jul 6, 2017 at 21:12 Ben Chernoff <[log in to unmask]> wrote:
>>>
>>> Hello FSL experts,
>>>
>>> I'm currently looking for an efficient way to draw an image/mask (.nii.gz) out of a large set of coordinates that I have in a 4D text file (x, y, z, and intensity value). Right now I have a very inefficient method whereby I have to loop over each row of the text file and run fslmaths for each coordinate and use -add with -roi to add the intensity value of a single value to a zero'd version of the anatomy, and then that resulting image gets added to the previous one:
>>>
>>> fslmaths <anatomy.nii.gz> -mul 0 -add <intensity> -roi <x> 1 <y> 1 <z> 1 0 1 <temp.niii.gz>
>>> fslmaths <sum.nii.gz> -add <temp.nii.gz> <sum.nii.gz>
>>>
>>> With hundreds of thousands of coordinates, this takes a very long time to run and I figure that surely there must be a more efficient way.
>>>
>>> For context, the intensity values in each voxel are correlation values between tractography results (35 subjects by n-voxels of the brain) and fMRI beta values (from the same 35 subjects). I perform the correlation using fslmeants to extract tractography results, concatenate subjects (common space) and then use MATLAB to correlate with the beta values in each voxel.
>>>
>>> Thanks in advance for any help!!
>>>
>>> -Ben Chernoff
>>
>> --
>> Niels Bergsland
>> Integration Director / Research Assistant Professor of Neurology
>> Buffalo Neuroimaging Analysis Center / University at Buffalo
>> 100 High St. Buffalo NY 14203
>> [log in to unmask]
>
> --
> Niels Bergsland
> Integration Director / Research Assistant Professor of Neurology
> Buffalo Neuroimaging Analysis Center / University at Buffalo
> 100 High St. Buffalo NY 14203
> [log in to unmask]
>
>



--
Niels Bergsland
Integration Director / Research Assistant Professor of Neurology
Buffalo Neuroimaging Analysis Center / University at Buffalo
100 High St. Buffalo NY 14203
[log in to unmask]