MRI and motion correction

Magnetic resonance imaging is sensitive to motion. Just like with other images, movement may cause blurring and distortion (‘artefacts’). To counteract this, motion correction methods are often used. These include devices that track motion as well as software that can correct some of the artefacts after the images have been collected. We have just published a paper on a potential new way to do this, using a wireless accelerometer (link, open access [1]), so here is a quick blog post about motion and MRI, explaining some of our findings along the way.

technologies-05-00006-g001The GE Firefly scanner, 3T

One of the reasons for doing this work is that we are using a new scanner for newborn babies. Motion is always an issue in MRI, even for adults, but the scanning of newborns may be particularly vulnerable. It is not always easy to convince a newborn baby to remain still. Newborns may move several centimetres where adults only shift a few millimetres. As the newborn is smaller in size, this movement also has greater impact in that it can completely displace the (much smaller) structure of interest. Newborn babies also show differences in physiology compared to adults, which can affect the scan. For example, they breathe faster and less regular, and the resulting motion is transmitted to the head to a greater degree (due to the smaller distance between head and chest) [2].

Types of motion
Motion comes in many types. There is microscopic motion, related to for example circulation of blood or water diffusion, and there is macroscopic motion, related to whole-body movement and physiological functions, for example breathing movement. It may be periodic (e.g. breathing movement), intermittent (e.g. yawns, hiccups) or continuous (e.g. general unsettledness, scanner vibrations). In research settings, noise and motion may be induced by experimental procedures [3]. Motion causes artefacts such as blurring, signal loss, loss of contrast and even the replication of signal in wrong places (‘ghosting’) – all lowering the quality of the image. An example of a motion artefact can be seen in the image below.

wireless_fig2Fast Spin Echo image. Left: no motion artefact; Right: artefact due to in-plane rotational head movement. Image from Paley et al. 2017. Technologies, 5(1); 6. (CC BY 4.0)

In the figure above, there are lines on the right-hand scan (red arrow), which are distortions. These distortions were created because the head rotated slightly whilst it was being scanned. Too much distortion and the image will become less useful for clinical and experimental purposes.

Types of motion correction
There are many types of MRI motion correction. The simplest may often be to prevent and minimise movement using coaching of the patient, sedation and fast and/or motion-resistant imaging protocols. A fast scan with a still individual will usually give very little motion. However, this may not always be possible. Patients do not always lie still, sedation may not always be a good idea, and even our best imaging sequences can be vulnerable to movement to some extent. Large movement is therefore often best tackled through different means: it is detected and corrected for. Correction can be done during the scan (real-time) or after the scan (creation of the image from the raw data and/or post-processing of the image).

There are limits to this type of large movement correction. For example, we can use so-called navigator pulses during the scan to correct for movement in real time, but they tend to make scans take much longer. We can also use tracking devices to correct for motion both during and after a scan, but such devices are limited by the level of motion they can detect and require a fair bit of extra equipment to work inside or interact with the scanner. Finally, we can correct for motion in reconstruction or post-processing, but this too usually takes a lot of time and effort. Which type(s) of correction method is best may differ between different types of scan, patients, and experimental protocols and so on.

In our paper, we used an external motion measuring device – a wireless accelerometer, similar to one that you may buy for fitness purposes – to measure motion of the head. The nice thing about this is that it can give us full real-time 3D motion information about how the head moves. It is not like a visual device, which needs a clear line of sight to be able to ‘observe’ the head at all times. The accelerometer gave us continuous, wireless feedback on the angle of the object being scanned. We could then use this information to adjust the MR data, using a motion correction algorithm. The algorithm, using movement data from the accelerometer, adjusted how the MR signal was recorded at each given time point. We were in short using the signal from the accelerometer to shift k-space.

This meant that shifts in signal due to movement could in theory be recorded and, at least partly, fixed. Conversely, it also meant that motion could be introduced in a motion-free image. To introduce motion, we first made a motion data file with the accelerometer, simply by manually rotating it and recording the angles. We then applied this motion data file to the raw data of a motion-free scan. The motion file was used to shift signal in k-space for each affected phase encode step. Doing this, we could distort the image in the same way that real motion would cause distortions, despite there being no original motion in the MR data. We could ramp this up as we pleased, adding more and more ‘motion’, as shown in the figure below.

wireless_fig3.jpg
MR images incorporating increasing amounts of motion. (a) Original no-motion image, (b-f) motion applied, starting with 2 × 10−2 radians (b) and doubled for each successive image. Image from Paley et al. 2017. Technologies, 5(1); 6. (CC BY 4.0)

In principle, reversal of the motion effects should be possible. The motion in the figure above was introduced using a standard rotation matrix which multiplied the k-space locations by the measured angle, and if we reverse this process (i.e. counter-rotate the k-space data according to the measured angles), removing the noise should be possible. As with most things, it is easier to break than fix, yet we did see a subtle reversal of motion artefacts for a simple side-to-side rotation. This means that a wireless accelerometer may eventually be used to retrospectively correct for motion in neonatal MRI scans. It is also possible that it could be used for guiding real-time correction methods.

References: 
1. Paley, M., Reynolds, S., Ismail, N., Herigstad, M., Jarvis, D. & Griffiths, P. Wireless Accelerometer for Neonatal MRI Motion Artifact Correction. Technologies. 2016; 5(1): 6. doi:10.3390/technologies5010006
2. Malamatenioua, C., Malika, S., Counsella, S., Allsopa, J., McGuinnessa, A., Hayata, T., Broadhousea, K., Nunesa, R., Ederiesc, A., Hajnala, J. & Rutherford, M. Motion-compensation techniques in neonatal and fetal MR imaging. Am J Neuroradiol. 2013; 34(6):1124-36.
3. Hayen, A., Herigstad, M., Kelly, M., Okell, T., Murphy, K., Wise, R., & Pattinson, K. The effects of altered intrathoracic pressure on resting cerebral blood flow and its response to visual stimulation. NeuroImage. 2012; 66: 479-488. doi: 10.1016/j.neuroimage.2012.10.049.

MRI and k-space

MRI images are created from raw data contained in a raw data space, called k-space. This is a matrix where MR signals are stored throughout the scan. K-space is considered a bit of a tricky topic, so I will only outline a brief explanation of what k-space is and how it relates to the MR image.

Kspace.pngThis is a visualisation of k-space.

K-space is what? The first thing to recognise is k-space is not a real space. It is a mathematical construct with a fancy name – a matrix used to store data. The data points are not simple numbers, they are spatial frequencies. Unlike ‘normal’ frequencies, which are repetitions per time, spatial frequencies are repetitions per distance. They are, in other words, waves in real space, like sound waves. We usually measure them as cycles (or line pairs) per mm. The number of cycles per mm is called the wavenumber, and the symbol used for wavenumber is ‘k’ – hence k-space.

It may be easiest to envision these spatial frequencies as variation in the brightness of the image (or variation in signal spatial distribution, if we are to get more technical). So we have a large matrix of brightness variations, which together makes up the complex image. The matrix is full when the image is completed (i.e. the scan is done).

kspace.jpg

K-space relates to the image how? The second thing to recognise is that k-space corresponds (although not directly) to the image. If the image size is 256 by 256, then the k-space will have 256 columns and 256 rows. This doesn’t mean, however, that the bottom right hand k-space spatial frequency holds the information for the bottom right hand image pixel. Each spatial frequency in k-space contains information about the entire final image. In short, the brightness of any given ‘spot’ in k-space indicates the amount that that particular spatial frequency contributes to the image. K-space is typically filled line by line (but we can also fill it in other ways).

Frequencies across k-space. Typically, the edges of k-space has high spatial frequency information compared to the centre. Higher spatial frequency gives us better resolution, and lower spatial frequencies better contrast information. Think of it like this: when you have abrupt changes in the image, you also get abrupt variations in brightness, which means high spatial frequencies. No abrupt changes means lower spatial frequencies. This in effect means that the middle of k-space contain one type of information about the image (contrast), and the edges contain another type of information (resolution/detail). If you reconstruct only the middle of k-space, you get all the contrast/signal (but no edges) – like a watercolour – and if you reconstruct only the edges of k-space, you get all edges (but no contrast) – like a line drawing. Put them together, however, we get all the information needed to create an image.

watercolour-1578069_960_720.jpg

Transformation: Notes and chords. The route from k-space to image is via a Fourier transform. The idea behind a Fourier transform is that any waveform signal can be split up in a series of components with different frequencies. A common analogy is the splitting up of a musical chord into the frequencies of its notes. Like notes, every value in k-space represents a wave of some frequency, amplitude and phase. All the separate bits of raw signal held in k-space (our notes) together can be transformed into the final MRI image (our chord, or perhaps better: the full tune). One important aspect of the Fourier transform is that it is not dependent on a ‘full’ k-space. We may leave out a few notes and still get the gist of the music, so to speak.

Cutting the k-space. We have types of scan that only collect parts of k-space. These are fast imaging sequences, but they have less signal to noise. Less signal to noise means that the amount of signal from the object being measured is reduced compared to the noise that we encounter when we image the object. We always get a certain amount of noise when imaging: from the scanner, the environment and sometimes also the object being imaged. A low signal to noise ratio is typically bad for image quality. Nevertheless, we can get away with collecting fewer lines in k-space when we image something relatively symmetrical, like a human brain. This allows us to mathematically fill in the missing lines in k-spaces, from an assumption of symmetry. Some fast scan sequences sample only every second line in k-space, and we can still reconstruct the image from the information gathered.

The problem of motion. If there was any motion during the scan, there will be inconsistencies in k-space. The scanner does not ‘know’ that the object moved, so it tries to reconstruct the image from data that is not consistent. This means that the reconstruction via the Fourier transform will be flawed, and we can get signal allocated to the wrong place, signal replicated where it should not be or signal missing altogether. We see this as distortions or ‘artefacts’ in the final image. As the data is collected over time, the longer the collection time, the more vulnerable the scan is to motion. Data collected in the phase encoding direction (which takes a relatively long time, see my previous post on gradients) is therefore more vulnerable than data collected in the frequency encoding direction. In a later blog post, I will discuss how we can use motion measurements to adjust the spatial frequencies k-space in a way that removes the effect of the movement. This is partly possible due to us not needing the full k-space to do a Fourier transform and get the image, as described above.

Summary. The take home message on k-space is as follows:

  1. K-space is a matrix for data storage with a fancy name.
  2. It holds the spatial frequencies of the entire scanned object (i.e. the variations in brightness for the object).
  3. We can reconstruct the image from this signal using a Fourier transform.
  4. The reconstruction can still work if we sample only parts of k-space, meaning that we can get images in much shorter time.
  5. Problems during data collection (i.e. motion) may cause errors in k-space that appears as ‘artefacts’ in the image after the Fourier transform.

 

Caveat. There is more to k-space than what I have described above, as a medical physicist would tell you. While it is good to have an appreciation of what k-space is and is not, a detailed understanding is generally not needed for those of us simply using MRI in our work rather than working on MRI. This post is meant as a brief(ish) introduction, not a detailed explanation, and contains some simplifications.

P-values for correlations in Excel

This is just a quick post to describe how to calculate p-values for two-variable correlations in Excel. Annoyingly, there is no direct way of doing this. Excel will give you the correlation, but not its associated p-value. It can be done, however, in a slightly roundabout way.

First, calculate the correlation between your groups:

=correl(variable1, variable2)

This gives you the sample test statistic r, which can be converted to t with the following formula:

temp2

where r is the correlation obtained above and n is your number of observations. Say you have 30 samples for two groups, and a r of 0.5. The calculation to obtain t is then (in excel terms):

=(0.5*sqrt(30-2))/(sqrt(1-0.5^2))
=3.05505

Then to assess the significance value associated with this t, simply use the tdist function (Student T distribution output):

=t.dist.2t(t, degrees of freedom)

This gives us results for a two-tailed distribution. Alternatively, the old tdist function can still be used, which requires the user to specify the number of tails (=tdist(t, degrees of freedom, #tails)).

Our calculation thus looks like this:

=t.dist.2t(3.05505, 30-2)
=0.0049

Which is the p-value for the correlation. Done!

excel-2010-logo

MATLAB for physiological analysis

I use MATLAB for my number crunching. While data acquisition and analysis programs such as Spike and LabChart have analysis functions that are good, they are not always appropriate for the type of analysis required. Also, I like to know all the calculations made on my raw data, and so my analysis tends to gravitate towards custom-made code. Dealing with time series for the most part, I’ve found MATLAB very useful, but it’s also handy for other types of data.

I therefore thought I’d compile a small list of things that has worked for me for the MATLAB novice looking to start using the program.

Learning MATLAB:

  1. Start small. Create a small matrix (e.g.20×20). Write code for processing your small matrix and make sure that it does what you expect it to do. Learn the basics on this matrix before touching real data.
  2. Break it. Error messages are great. Each message will lead to a better understanding of how to use MATLAB, so make sure you understand what they mean.
  3. Use the forum. MATLAB central will have many (if not all) the answers you can wish for (including: “what does my error message mean”). It’s a great resource! Link: http://uk.mathworks.com/matlabcentral/

Using MATLAB:

  1. Remember that MATLAB is only as good as its user. In many cases, you’ll get a number which might appear reasonable, but errors in your code can still be present. Getting an output does not mean that your code works the way you want.
  2. Learn to plot your data. Plot raw data and superimpose your calculations along the way. Mistakes should be easy to visualise, at least when working with time series. This is an easy quality check and has spared me some embarrassing mistakes in the past. Also, the figures you get can be made quite attractive for publication purposes. Certainly prettier than MS Excel, at least.
  3. Run the code on a known data set first. Make sure that the code produces the results you would expect. Again, this is a simple thing that can spare you a lot of grief. Compare with in-built programs if possible (such as spike detection in LabChart versus custom-written spike detection in MATLAB).
  4. Understand which computations are better done manually. Small, one-off computations could require more work coding up than just processing manually. The point of the exercise is to make things easier, not harder.
  5. Learn how to run a series of analyses with one click. Sometimes you’ll need to run many subjects in quick succession. Writing code that reads a list of subject numbers (one click) and automatically loops through the analysis process for each line on the list is one way of doing this that has saved me some time in the past.

Automated analysis can be very useful as it is less time consuming in the long run and you reduce the risk of silly, manual mistakes (typos etc.). With a few clicks, you could run all your number crunching in the background whilst you have your morning coffee and try to wake up your brain. Sounds good, eh? It also helps you understand the data better. For example, if you want to calculate a waveform mean, you have to know the mathematical formula for doing so. In an in-built program, this would not be needed. In short, it can be very helpful, when done right.

A few other things:

  1. Text files are good. Text files (.txt or .dat) are quite easy to work with in MATLAB. Save raw data in one of these simple formats as well as the custom format.
  2. Company is better. If there is someone else around that knows or wants to learn, join forces. It’s much more fun that way.
  3. Annotation is the best. Annotate and annotate well. Your future self thanks you! Trust me on this. A few simple %this-is-what-this-line-does will make your life infinitely easier.

If you’re not certain about using MATLAB, there’s a 30-day trial version available that you can play with to figure out if it is for you. It’ll take a little while to get to grips with if you’re not used to this type of program, but it’s worth the time.

161px-Matlab_Logo