[FieldTrip] difficulty with nifti format and ft_write_volume

Jen Whitman jenwhitman at gmail.com
Mon Feb 28 20:59:28 CET 2011


Hello Jan,

When calling volumesegment, I specified 'ctf' as the coordinate system. The
function I wrote to call volumesegment and prepare_singleshell for each
subject and save the results is pasted below, with a couple of  comments
added for clarity.
Over the weekend I tried specifying the coordinate system in the call to
ft_volumenormalise as 'ctf' rather than 'spm', and commented out all the
lines that said cfg.spmversion = 'spm8'; before calling a function. However,
that created worse results, as each plot involved stripes of activation and
empty voxels, suggesting that 'ctf' was not the correct coordinate system to
specify.

Thanks for the attached script. Looking in that the comments in that, I
suspect that the solution to my problems will be to specify my filetype as
nifti_img rather than nifti. I'll let you know how that goes.

Jen

------------------------------------------------------------------------------------------------------------
% the variable subj is simply a string consisting of a subject number (e.g.
's05') which can be a folder name or part of a filename
function [vol mri segmentedmri
segmentedmriF]=call_volume_segment_function_spm8(subj)
cfg.spmversion = 'spm8';
cfg.template   = '/home/woodwardlab/spm8/templates/EPI.nii';
%cfg.template='/home/common/matlab/spm2/templates/T1.mnc';
cfg.name=[subj '_volseg'];
cfg.write='yes';
cfg.smooth='no';
cfg.coordinates='ctf';
mri=read_mri([subj '/mri/' subj 'head.mri']); % made with CTF mriConverter
and mriViewer software, after fiducials were marked
segmentedmri = volumesegment(cfg, mri);
segmentedmriF = segmentedmri;
segmentedmriF.gray  = flipdim(flipdim(flipdim(segmentedmriF.gray,3),2),1);
segmentedmriF.white = flipdim(flipdim(flipdim(segmentedmriF.white,3),2),1);
segmentedmriF.csf   = flipdim(flipdim(flipdim(segmentedmriF.csf,3),2),1);
segmentedmriF.transform = mri.transform;
segmentedmriF.anatomy   = mri.anatomy;
cfg = [];
cfg.spmversion = 'spm8';
vol = prepare_singleshell(cfg, segmentedmriF);
eval(['save ' subj '/meg/mrisegmented.mat mri segmentedmri segmentedmriF
vol'])



On Sat, Feb 26, 2011 at 5:26 AM, jan-mathijs schoffelen <
jan.schoffelen at donders.ru.nl> wrote:

> Dear Jen,
>
> I do not manage to reproduce your issue, when only focussing on the
> ft_volumewrite and visualization part of your pipeline. See attached script,
> and yet an updated version of ft_volumewrite which you need to (hopefully)
> draw the same conclusion as I did.
> Yet, I only now realize that your question may pertain to the entire
> pipeline. It could be that something is going wrong there.
> I only see now that in the part of your script of which you reported that
> it gave 'good' results, you specify cfg.coordinates = 'ctf' before calling
> ft_volumenormalise. I assume this is correct, because the coordinate system
> your source-reconstructed data lives in, is according to the CTF-convention,
> and not according to the SPM-convention. On the other hand, the template for
> the spatial normalization lives in the SPM-coordinate system. In order for
> the spatial normalization to work OK, Fieldtrip tries to convert from one
> coordinate system to the other (once again, this is appropriate behaviour),
> before doing the actual normalization. It seems that at least in the script
> you sent along, in the final (not working version), you specified
> cfg.coordinates = 'spm' prior to calling ft_volumenormalise. This is
> probably wrong.
> Another important point that should be mentioned, is that the coordinate
> systems in which the functional data and the anatomical data live should be
> the same for the ft_sourceinterpolate to make sense. In other words, if your
> source reconstructed images are defined on a 3D grid of positions in
> CTF-space, the mri.transform of your anatomy should describe a
> transformation from voxel to CTF-space.
> I think you may want to revisit step by step this part of the pipeline; I
> don't think the problem lies in the writing.
> A final possibility of course is that Mricron is misbehaving...
>
> Best,
>
> Jan-Mathijs
>
>
>
>
>
>
> On Feb 25, 2011, at 9:44 PM, Jen Whitman wrote:
>
> Hi Jan,
>
> I tried re-running the analysis with the new script you sent me, and the
> latest version of fieldtrip (since I needed ft_get_opt as well), but the
> spm8 images being written are still producing flawed results. It's the same
> problem as I mentioned briefly in my previous post. I am not getting any
> error messages when writing these images. Rather, my problem is that the
> spm8 and spm2 results from the same data ought to be identical when viewed
> in mricron, but they're far from it. When I use mricron to look at the
> results from the spm8-format images, combined across participants to create
> a t-image, I just get a single 'blob' spanning roughly half the brain. In
> contrast, when I used spm2-format previously on the same data, the t-image
> was much more meaningful; a posterior alpha power decrease in a set of
> regions corresponding to the 'task-positive network' (a network found in the
> results of an fMRI version of my experiment, and widely reported in the fMRI
> literature).
>
> This failure to replicate the spm2 results when using spm8 images from the
> same data leads me to suspect that something is wrong with the coordinates
> for spm8 format. However, after experimenting extensively with different cfg
> options I still haven't identified the problem. If I my structural MRIs have
> been saved to .mri files using CTF's MRIConverter program, which cfg
> options, particularly for coordinates, template images, and filetypes,
> should I specify before calling the ft_volumesegment,
> ft_prepare_singleshell, ft_sourceinterpolate, ft_volumenormalise, and
> ft_volumewrite functions? Or should I be calling a different set of
> functions now?
>
> Thanks again for your help,
>
> Jen
>
> On Thu, Feb 24, 2011 at 10:07 AM, Jen Whitman <jenwhitman at gmail.com>wrote:
>
>> Great, thanks!
>>
>> I'll start the analysis with your new script today and will let you know
>> how it works out.
>>
>> Jen
>>
>> On Thu, Feb 24, 2011 at 4:44 AM, jan-mathijs schoffelen <
>> jan.schoffelen at donders.ru.nl> wrote:
>>
>>> Dear Jen,
>>>
>>> I managed to reproduce your problem. The code was rather buggy and indeed
>>> ft_volumewrite did not behave as it should have. I now fixed it in the code
>>> and it should run fine now. Please find the updated file attached. It will
>>> be available on our ftp-server as of tonight. Please note that I updated the
>>> documentation, and changed the names of some of the options a bit. If you
>>> want to save your data in analyze-format, you should specify cfg.filetype =
>>> 'analyze_spm'. If you specify cfg.filetype = 'nifti', it should write out a
>>> volume to nifti-format, using SPM8.
>>>
>>> Best wishes,
>>>
>>> Jan-Mathijs
>>>
>>>
>>>
>>>
>>>
>>> On Feb 23, 2011, at 7:44 PM, Jen Whitman wrote:
>>>
>>>
>>> Dear Jan,
>>>
>>> Thanks for the quick reply. Yes, I have tried it out quite a few times
>>> now, experimenting with different settings in the cfgs. Below I'll paste the
>>> code I've been using to write images - first the code that successfully
>>> created spm2 images that produced good results, then the code used for
>>> creating nifti format images from the same data. The comments in this second
>>> part are at this point a bit of a maze of cfg options I've been changing
>>> back & forth. Any insights/suggestions regarding how to set up my cfgs to
>>> make this work would be greatly appreciated.
>>>
>>> Jen
>>>
>>>
>>> %%%%%%%% this code generated spm2-compatible images which did work
>>> (producing results that made sense).
>>>
>>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>>
>>>     sourcetemp.avg.pow = (sourcetemp.avg.pow - sourcePre.avg.pow) ./
>>> sourcePre.avg.pow;
>>>
>>>     cfg = [];
>>>     cfg.downsample = 2;
>>>     sourcetempInt = sourceinterpolate(cfg, sourcetemp , mri);
>>>
>>>     % projecting the plot onto a surface...
>>>     cfg = [];
>>>     cfg.coordinates  = 'ctf';
>>>     cfg.template     = '/home/common/matlab/spm2/templates/T1.mnc'; %this
>>> template is in MNI coordinates
>>>     sourcetempIntN = volumenormalise(cfg, sourcetempInt);
>>>
>>>     filename=[subj 'run' int2str(r) 'cond' int2str(cond) '_' int2str(f)
>>> 'HzWin' int2str(win) 'width750ms'];
>>>     cfg=[];
>>>     cfg.parameter     = 'avg.pow'; % string, describing the functional
>>> data to be processed, e.g. 'pow', 'coh' or 'nai'
>>>     cfg.filename      = [filename '.img']; %'testimageoutput_alphafreq';
>>> % filename without the extension
>>>     cfg.filetype      = 'spm'; %'analyze', 'spm', 'vmp' or 'vmr'
>>>     cfg.coordinates   = 'spm'; %'spm, 'ctf' or empty for interactive
>>> (default = [])
>>>     cfg.datatype = 'double'; %'float'; %'double'; %'bit1', 'uint8',
>>> 'int16', 'int32', 'float' or 'double'
>>>
>>>     volumewrite(cfg, sourcetempIntN)
>>>
>>>
>>>
>>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>>
>>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>>
>>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>>
>>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>> %%%%% this code below hasn't worked yet...
>>>
>>> % I added    cfg.spmversion = 'spm8';
>>> % in the cfgs for the calls to ft_prepare_leadfield and
>>> ft_sourceanalysis,
>>> % and in the call to prepare_singleshell after calling volumesegment
>>>
>>> % I've also ensured that spm8 is the only spm version in my path, even in
>>> % the fieldtrip/external folder, and ensured that spm8 is installed
>>> properly
>>> % (files compiled correctly, etc..)
>>>
>>>     sourcetemp.avg.pow = (sourcetemp.avg.pow - sourcePre.avg.pow) ./
>>> sourcePre.avg.pow;
>>>
>>>     filename=[subj 'run' int2str(r) 'cond' int2str(cond) '_' int2str(f)
>>> 'Hzspm8_FIXv9_Win' int2str(win) 'width750ms.img'];
>>>
>>>     cfg = [];
>>> %     cfg.coordinates  = 'spm'; % changed for version 5
>>> %     cfg.spmversion = 'spm8'; % changed for version 5
>>>     cfg.downsample = 4;
>>>     sourcetempInt = ft_sourceinterpolate(cfg, sourcetemp , mri);
>>>
>>>
>>>     % projecting the plot onto a surface...
>>>     cfg = [];
>>>     %cfg.coordinates  = 'spm'; % changed for version 5
>>>     %cfg.coordinates  = 'ctf'; % changed for version 5
>>>     cfg.coordinates = 'spm'; % changed back to spm for version 9
>>>     cfg.downsample = 4;
>>>     %cfg.spmversion = 'spm8'; % changed for version 6 (because this gets
>>> specified in volumewrite)
>>>     cfg.template = 'Hmatrix/mask.nii.nii'; % basically equivalent to
>>> using spm8/templates/EPI.nii, except that mask.nii (produced from fmri data)
>>> has the desired voxel size
>>>     % cfg.name = [filename]; % changed for version 6
>>>     %cfg.write= 'yes'; % changed for version 6 (when this was set to
>>> 'yes' there was no subsequent call to volumewrite)
>>>     cfg.write= 'no';   % changed for version 6
>>>     sourcetempIntN = ft_volumenormalise(cfg, sourcetempInt);
>>>
>>>     % this whole cfg and function call added for version 6
>>>     cfg=[];
>>>     %   cfg.parameter     = string, describing the functional data to be
>>> processed, e.g. 'pow', 'coh' or 'nai'
>>> %   cfg.filename      = filename without the extension
>>> %   cfg.filetype      = 'analyze', 'spm', 'vmp' or 'vmr'
>>> %   cfg.vmpversion    = 1 or 2 (default) version of the vmp-format to use
>>> %   cfg.coordinates   = 'spm, 'ctf' or empty for interactive (default =
>>> [])
>>>     cfg.parameter='pow';
>>>     cfg.filename=filename;
>>>     cfg.filetype = 'spm';
>>>     cfg.spmversion = 'SPM8'; % capitalized after first error message from
>>> vers 6
>>> %   cfg.dataformat='nifti';  % added after first error message from vers
>>> 6
>>>                                  % commented out after 2nd error message
>>> from vers 6
>>>     %cfg.vmpversion=2; % this is a filetype, like spm, so don't need to
>>> specify unless cfg.filetyp='vmp'
>>>     cfg.coordinates='spm';
>>>     ft_volumewrite(cfg,sourcetempIntN);
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Feb 23, 2011 at 7:50 AM, jan-mathijs schoffelen <
>>> jan.schoffelen at donders.ru.nl> wrote:
>>>
>>>> Dear Jen,
>>>>
>>>> I notice that indeed in the documentation section of ft_write_volume
>>>> there is a FIXME behind nifti. Yet, nifti format seems to be supported by
>>>> ft_write_volume (at least in a recent version of fieldtrip). Did you try it
>>>> at all (and ran into problems) or were you held back by the FIXME statement?
>>>> Could you just try it out using a recent fieldtrip function?
>>>>
>>>> Thanks and best wishes
>>>>
>>>> Jan-Mathijs
>>>>
>>>>
>>>>
>>>> On Feb 23, 2011, at 2:21 AM, Jen Whitman wrote:
>>>>
>>>>  Hello,
>>>>>
>>>>> While writing beamformed images to spm2 format in a previous version of
>>>>> fieldtrip (now lost due to a computer crash), I was able to get nice-looking
>>>>> results; networks of brain regions consistent with existing literature. When
>>>>> I try to write images from the same dataset and the same analysis to spm8
>>>>> format, my results (t-images computed across subjects) end up being single
>>>>> clusters spanning large sections of the brain (e.g. a 'blob' spanning all of
>>>>> one hemisphere but not the other). Unfortunately, some aspects of my planned
>>>>> data analyses cannot be performed on spm2 images, so I have to find a way of
>>>>> writing to successfully to nifti format.
>>>>>
>>>>> I just noticed that in the comments in the ft_write_volume function,
>>>>> which I am calling via ft_volumewrite, it says 'FIXME' next to nifti under
>>>>> the list of supported dataformats. Is there by any chance a patch out there
>>>>> for writing nifti images?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> _______________________________________________
>>>>> fieldtrip mailing list
>>>>> fieldtrip at donders.ru.nl
>>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>
>>>>
>>>> Dr. J.M. (Jan-Mathijs) Schoffelen
>>>> Donders Institute for Brain, Cognition and Behaviour,
>>>> Centre for Cognitive Neuroimaging,
>>>> Radboud University Nijmegen, The Netherlands
>>>> J.Schoffelen at donders.ru.nl
>>>> Telephone: 0031-24-3614793
>>>>
>>>> _______________________________________________
>>>> fieldtrip mailing list
>>>> fieldtrip at donders.ru.nl
>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>
>>>
>>> _______________________________________________
>>> fieldtrip mailing list
>>> fieldtrip at donders.ru.nl
>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>
>>>
>>>  Dr. J.M. (Jan-Mathijs) Schoffelen
>>> Donders Institute for Brain, Cognition and Behaviour,
>>> Centre for Cognitive Neuroimaging,
>>> Radboud University Nijmegen, The Netherlands
>>> J.Schoffelen at donders.ru.nl
>>> Telephone: 0031-24-3614793
>>>
>>>
>>> _______________________________________________
>>> fieldtrip mailing list
>>> fieldtrip at donders.ru.nl
>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>
>>
>>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
> Dr. J.M. (Jan-Mathijs) Schoffelen
> Donders Institute for Brain, Cognition and Behaviour,
> Centre for Cognitive Neuroimaging,
> Radboud University Nijmegen, The Netherlands
> J.Schoffelen at donders.ru.nl
> Telephone: 0031-24-3614793
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20110228/92c50c51/attachment-0002.html>


More information about the fieldtrip mailing list