JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for FSL Archives


FSL Archives

FSL Archives


FSL@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

FSL Home

FSL Home

FSL  August 2013

FSL August 2013

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: topup with non diffusion sequences

From:

Franz Liem <[log in to unmask]>

Reply-To:

FSL - FMRIB's Software Library <[log in to unmask]>

Date:

Tue, 13 Aug 2013 16:56:43 +0200

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (175 lines)

Dear Jesper and Michael,

thank you so much for the replies and the code.
I am aware that those approaches are far from optimal. That's why I am going to record blipupdown images in the future.

Jesper, the data I am working on are from an ongoing longitudinal study. For the second time point (1 year after the first) we are acquiring blipupdown b=0 images. Using the reverse blipped time point 2 b=0 images for correction of TP1 directly probably won't work. However, do you think that the following might work, or would this introduce some bias:
*For the 2nd time point, unwarp the blipped b=0 with topup as it is intended to be used. This would produce an unwarped b=0 image.
*Use this unwarped b=0 for correction of the 1st time point: feed the distorted TP1 b=0 and the unwarped TP2 b=0 into topup (with a readout time very close to zero for the unwarped image).
Sorry for taking topup for a ride so far from home.

Thanks so much for your help,
Franz

  
Am 12.08.2013 um 21:28 schrieb Michael Dwyer:

> Hi Franz,
> 
> I disavow all responsibility for the results, but here is a very dirty kludge that might help. I'm copying in a small python script I've used to non-linearly map intensities from one image to another. It essentially voxel-wise regresses the intensities using a K-nearest neighbor approach. Obviously it's no substitute for what Jesper is suggesting, but it might help with retrospective data. It'll sort of "predict" what the B0 would look like if you made it from the T2w.
> 
> Copy the below into a file called similarize_intensities.py, and then run:
> 
> ./similarize_intensities.py t2w.nii.gz b0.nii.gz t2w_as_b0.nii.gz
> 
> N.B. Please make sure you use INTEGER values, or it will never finish. So, run the raw files through fslmaths with "-odt int". Also a little smoothing (around 0.5mm) might help stability. Also, the images need to be co-registered first for this to work, but from your context I assume this is already the case.
> 
> =========== CODE===================
> 
> #!/bin/env python
> 
> import optparse
> import numpy
> import nibabel
> from sklearn.neighbors import KNeighborsRegressor
> from scipy import ndimage
> 
> # Set up the option parser to handle the command-line
> usage = """%prog [options] source-img target-img output-image"
> 
> This program takes two images, source and target. It determines a non-linear
> mapping from intensities in source to target, and then remaps source 
> accordingly. It uses a nearest neighbors regressor to do so. Theoretically,
> the "successfulness" of this operation depends on the joint histogram entropy.
> 
> Warning: this program is BNAC VRMQC, and should be used with appropriate
> caution. It is not designed for use without manual review of the 
> outputs."""
> parser = optparse.OptionParser(usage=usage)
> 
> parser.add_option("-v", "--verbose", dest="verbose",
>         help="Increase verbosity", action="store_true", default=False)
> 
> parser.add_option("-d", "--downsample-factor", dest="ds_factor",
>         type="float", help="Spatial downsampling factor (0.25)", 
>         metavar="FACTOR",
>         default = 0.25)
> 
> (options, args) = parser.parse_args()
> if len(args) != 3:
>     print "You must supply source, target, and output image names"
>     exit()
> 
> if options.verbose:
>     def vprint(*args):
>         # Print each argument separately so caller doesn't need to
>         # stuff everything to be printed into a single string
>         for arg in args:
>            print arg,
>         print
> else:   
>     vprint = lambda *a: None      # do-nothing function
> 
> # Load up the images with Nibabel
> vprint("Loading source images")
> img1 = nibabel.load(args[0])
> img2 = nibabel.load(args[1])
> 
> # Get the actual data
> data1 = img1.get_data()
> data2 = img2.get_data()
> 
> # K-neighbors algorithms aren't the fastest, so we downsample. It's 3D, so
> # the factor will be df_factor^3 -- a substantial speedup.
> vprint("Downsampling data by a factor of ", options.ds_factor)
> data1_small = ndimage.zoom(data1,options.ds_factor)
> data2_small = ndimage.zoom(data2,options.ds_factor)
> 
> # Assume the images are already deskulled, so don't include 0's.
> vprint("Removing voxels with 0 intensity")
> data1_cut = data1_small[data1_small != 0]
> data2_cut = data2_small[data1_small != 0]
> data1_cut_f = data1_cut.flatten()
> data2_cut_f = data2_cut.flatten()
> 
> # Set up a scikit-based K-nearest neighbors regressor
> neigh = KNeighborsRegressor()
> vprint("Fitting model")
> neigh.fit(numpy.transpose(numpy.atleast_2d(data1_cut_f)),data2_cut_f)
> 
> 
> # To speed things up, since there are many less intensities than voxels, we
> # first create a lookup table.
> vprint("Creating lookup table")
> full_data1 = numpy.transpose(numpy.atleast_2d(data1.flatten()))
> vals = numpy.sort(numpy.unique(full_data1))
> dvals = numpy.transpose(numpy.atleast_2d(vals))
> predvals = neigh.predict(dvals)
> vdict = dict(numpy.vstack((vals, predvals)).T)
> vdict[0] = 0
> 
> # Then apply the table to the raw source image data
> vprint("Applying transform")
> data1_trans = [(vdict[i]) for i in data1.flatten()]
> data1_trans_3d = numpy.reshape(data1_trans, data1.shape)
> 
> # Save the output file
> vprint("Saving output")
> oimg = nibabel.Nifti1Image(data1_trans_3d, img1.get_affine())
> nibabel.save(oimg, args[2])
> 
> ========END CODE===================
> 
> 
> 
> 
> On Mon, Aug 12, 2013 at 11:55 AM, Jesper Andersson <[log in to unmask]> wrote:
> Dear Franz,
> 
>> I have a set of diffusion data without fieldmaps or reverse-blips and would like to perform distortion correction. A couple of months ago, there was a thread started by Mark where Jesper proposed to use T2w images with topup to correct for distortions in the DWIs (Andreas was interested as well)(https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=FSL;b7e1c3eb.1303). 
>> I tried the same with not terrible but also not great results. It would be great if someone has suggestions on optimizing this workflow or share their experience about what works and what does not.
>> 
>> My DWI are 2x2x2mm, my T2w is 0.5x0.5x5mm 
>> I brought the T2w into DWI space (dof=6; matrix was calculated with beted images, but the unbeted images were transformed).
>> Then I proceeded as described in the previous thread. 
>> 
>> I have a single subject with blip-up-down b=0 images as ground truth, however, the goal is to perform the correction without these as I don't have them for the most subjects. I have attached a my_topup_results_fieldcoef for the t2w approach and the blip-up-down b=0.
>> What worries me is that for the t2w images the fieldcoef seems considerable less smooth than for the blip-up-down images.
> 
> this is not the intended use of topup. topup is built on the assumption that the signal in the two images is identical, except for some geometric distortions (including subject movement). Hence, any difference topup sees it will try to "fix" by applying a geometric transform.
> 
> When you have two images acquired with the same sequence, but with some change in phase-encoding this assumption is likely to be (almost) true. When you have two different sequences you need to be very lucky for it to work well as there will be all sorts of signal changes that are unrelated to geometric distortions (in addition to those actually caused by geometric distortions).
> 
> I think the additional structure in your "estimated field" is due to topup trying to compensate for differences in contrast by applying a geometric transform.
> 
> There have been a couple of cases of people that have reported useful results from registering a SE-EPI to a T2 weighted non-EPI image, but there will not be any guarantees that it will work. Chances are it will work for some T2 sequences/images and not for others.
> 
> It takes very little time to acquire an additional SE-EPI image, much less than to acquire a T2 image, so I strongly recommend doing that.
> 
> Jesper
> 
>> Do you think that slice thickness of 5mm is too large to use the T2w?
>> 
>> Alternatively, is there a hack to use T1w images (1x1x1mm) or the EPIs from the resting state sequence. The RS EPIs are acquired with a different total readout time than the DWIs but also with a fast field echo single-shot sequence (the DWIs are spin echo single-shots).
>> 
>> 
>> Any help is very much appreciated.
>> Best,
>> Franz
>> 
>> <t2w_my_topup_results_fieldcoef.png>
>> <blipupdown_my_topup_results_fieldcoef.png>
>> 
>> 
> 
> 
> 
> 
> -- 
> Michael Dwyer
> Director of Technical Imaging Development
> Buffalo Neuroimaging Analysis Center
> 100 High St. Buffalo NY 14203
> [log in to unmask]
> (716) 859-7065

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager