How to make artificial lesions (python + FSL)

Taylor Hanayik
The Image
Published in
6 min readSep 12, 2018

Working with neuroimaging data from stroke participants presents many challenges. Stroke related brain injury can present with varying levels of severity, and extent of damage. Sometimes creating datasets with artificially placed lesions can help assess, and develop image registration methods.

An example of an artificially lesioned brain image. A real lesion from a stroke survivor was “injected” into a neurologically healthy individual’s brain image.

TL;DR

You can use my Github code to make your own datasets with artificial lesions. This is used primarily to assess stroke image registration methods for robustness and quality.

Data requirements

Stroke MRI data: T1w scan, T2w scan, Lesion image (assumed to be traced from T2w scan)

Control data: T1w scan (ideally matched to age range of stroke lesion “donor”

Python processing requirements (non standard packages)

Python 3.6 or >, nibabel, nilearn, numpy, scipy

Other software needed

FSL

My processing code with example data

Overview

One of the key concerns in analyzing brain images with injury is how that injury affects the quality of output from image processing steps. For example, some nonlinear image registration methods will effectively shrink lesioned tissue in order to better match a template image (e.g. MNI152-T1w scan). Even if lesion shrinkage can be avoided, there is the remaining concern that voxels within the injured area will be abnormally displaced relative to the expected voxel displacement when registering a neurologically healthy brain image to a template.

Here, what I mean by displacement is how the registration algorithms have chosen to move particular voxels in order to best match their counterparts in a template image. For example, imagine two pictures taken with a camera phone. One picture is of your face, with both eyes open, and the other picture is identical in every way except that you closed one eye. Now, how would an image registration algorithm match your eyes between the two pictures? How is the location of the open eye computed when the other image has limited information to match to (one eye closed)?

We face this same problem in analyzing data from brain injured participants. Brain injuries such as stroke result in missing, or abnormal tissue compared to an age matched neurologically healthy individual. How is the tissue within the boundaries of the lesion displaced relative to a healthy version of the same image?

Method

A dataset of artificially lesioned images affords some advantages over a dataset of only naturally lesioned brain images. In particular, we can directly compare normalization performance with and without a lesion within the same individual. This is not possible in data from participants where the lesion has occurred naturally (we rarely have an MRI before injury). Furthermore, we can generate datasets that are orders of magnitude larger, since we can apply artificial lesions from every stroke participant’s image to every control participant’s image. If all combinations are exhausted, datasets that began with hundreds of images will combine to create thousands of images. This can enhance our estimations of normalization performance metrics, although many images will end up containing similar features (e.g. the same lesion placed in all healthy control images will now make them related). A small price to pay.

My method to artificially lesion brain images used similar procedures to previous studies (Brett et al., 2001; Nachev et al., 2008). However, some useful steps were also added. All processing (except for manual lesion tracing) was automated with custom developed Python functions that interact with multiple additional programs (namely FSL, which must be installed).

Step 1

Lesions masks need to be manually traced by experienced neuroimagers on each stroke participant’s T2w image. Injury is often more apparent in these images. Next, each lesioned image, as well as the control image was reoriented to the stereotaxic coordinate system defined by the MNI152 template using FSL’s “reorient2std” program. This reorientation does not perform any calculations or data interpolation, but merely ensures all images conform to a standardized data organization format and anatomical directions are consistent.

Step 2

The T1w lesion image and T1w control image are then cropped in the head-foot direction to remove extraneous non-brain tissues (e.g. neck) using FSL’s “robustfov” program. This also reduces file size (useful when you have thousands of images).

Step 3

Next, the lesioned T2w image is registered to the lesioned T1w image using rigid body registration (6 DOF) with FSL’s FLIRT program (Jenkinson & Smith, 2001). The computed registration parameters are applied to the manually traced lesion mask generated from the T2w image and results in a mask that now conforms to the space defined by the T1w image. Due to interpolation effects, the lesion is then re-binarized using a threshold of 0.5.

Step 4

Next, the lesion mask is smoothed using a full-width half maximum (FWHM) of 3 mm. Smoothing generates a gradient from 1 to 0 only near the edges of the mask (feathering). The lesion mask is then mirrored to the undamaged hemisphere of the lesioned T1w image and the enantiomorphic lesion filling (Nachev et al., 2008) method is used to “heal” the lesioned T1w image. This step is crucial, and strays from previous methods used to create artificially lesioned brain images. The enantiomorphic healing is necessary to facilitate a decent brain extraction (e.g. skull stripping) of the lesioned T1w image.

Step 5

Brain extraction is carried out using FSL’s “bet” (Smith, 2002) with a fractional intensity value of 0.4 which is more conservative than the default value, thus preserving more true brain signal. The same brain extraction is also carried out on the control T1w image. Then, the lesioned T1w image (brain only) is linearly (full affine, 12 DOF) registered to the control T1w brain using trilinear interpolation with FSL’s FLIRT. By removing non-brain tissue prior to this registration step, we can ensure a more accurate fit since the cost function will be driven by brain tissue instead of non-brain tissue (e.g. skull). These registration parameters computed from FLIRT are then used to register the lesion mask to the control T1w image space as well. The brain-to-brain registration parameters are also used to then register the whole head lesioned T1w image to the space of the control T1w image.

Step 6

Next, both T1w images (control and lesioned) are matched for intensity using mean scaling so that when tissue from the lesioned imaged is placed into the control image the result will not be abnormally dark or bright.

Step 7

The lesion mask is then smoothed using a FWHM of 8 mm, which facilitates a gradual blending of tissues near the edges of the lesion when it is injected into the control image. This large smoothing value also allows us to include enlarged ventricles when they are present, further making the artificially lesioned brain more representative of the effects related to a natural lesion. Lastly, tissue from the lesioned T1w image within the mask is placed into the control T1w image, and blended via the gradient present near the edges of the mask.

Together, all of the artificial lesioning steps are performed using an exhaustive pairwise combination of control images and lesioned images to generate a dataset much larger than the naturally lesioned dataset alone. The resulting dataset contains whole head images (including skull) with real lesions “donated” into a cohort of age matched, healthy control participants. All images are processed identically, and with minimal interpolation. Therefore, there should be no systematic difference introduced in the artificial dataset prior to comparing image registration methods (e.g SPM new-seg, FLIRT, DARTEL, ANTs SyN).

Link to the Github project containing all the python code to do the steps described above

--

--

Taylor Hanayik
The Image

Software engineer at the University of Oxford. I design and develop software for neuroimaging research.