Liz: Today’s guest post comes from Matt Hall at UCL. Call me easily impressed, but blimey, this is good. Thank you Matt!
There’s no denying that people are doing some pretty amazing things with their Raspis. Touch screens, different OS’s, robots – this little beastie is certainly adaptable. When I unwrapped mine on Christmas morning I was very excited, and immediately started thinking about how I could put it through its paces – I thought about games and art apps but then I thought “Hold on a tick Matt, aren’t you a research scientist working on medical image analysis? Don’t you maintain an MRI image analysis toolkit? Let’s throw down the gauntlet and see if we can do some proper image analysis.”
Oh, yes of course. Silly me.
How about full-scale state-of-the-art medical image processing on the Raspberry Pi?
What’s it all about?
I work at the UCL Centre for Medical Image Computing (CMIC) in the Microstructure Imaging Group. We’re a team of scientists developing mathematical modelling and advanced computational techniques to analyse Diffusion MRI data. What’s Diffusion MRI? It’s a special kind of MRI imaging that is sensitive to the way water is moving around in the brain (it doesn’t have to be the brain, but brains are pretty interesting to look at, so it usually is). Water motion is interesting to look at because of the things that get in the way of the water. For water in the brain, the thing getting in the way is (you guessed it) the brain.
By looking at the way the water moves, we can get a picture of the stuff getting in the way and learn about the brain. Our work is aimed at using an MRI machine like a microscope. With a normal microscope you have to cut things open and remove bits of tissue before you can look at them, but the scanner can look inside the body without damaging it – a non-invasive microscope.
We’ve build a software toolkit that analyses this kind of data. It’s called Camino, it’s written in Java and designed to run in a Linux-like environment so getting it to run on the Raspi isn’t a completely crazy idea.
Getting it working
So I rolled up my sleeves and had a go. This sort of thing is very calculation-heavy, so I needed to get mathematical code running as fast as possible. This meant finding a Java distribution that would do the maths in hardware, not software. Unfortunately, the usual Java for ARM didn’t do this, but as luck would have it, just as I realised that this might be a problem the nice people at Oracle released the Java 8 for ARM developer’s preview, which did the job nicely. After downloading and installing, I now had an efficient Java environment.
Next, I downloaded Camino and installed it. It compiled first time with no errors – Java can be a wonderful thing sometimes!
After setting a few path variables I was ready to go. Except for one small detail: data. I needed something to analyse! Fortunately, Camino also provides a test dataset. It’s a set of 3D diffusion MR images of a healthy human brain. It’s also available online, so I downloaded this too. Good old Midori.
Making some images
I wanted to try the same sort of analysis that a researcher working in my field might want to use. The simplest and most widely used technique in Diffusion MRI is called Diffusion Tensor Imaging (DTI). The brain is partly made up of a thing called white matter, which is a lot like cabling that connects various bits of it together. DTI can tell us which way the cables are pointing at each point along their length. We can use the information it gives us to make new images which are more useful than the originals.
To my great delight, the Raspi ran a DTI analysis in a little over 5 minutes and produced some really nice images. All these images were generated and displayed by the Raspi. (Liz: you can enlarge all these images by clicking on them.) I used scrot for screen captures, so aside from a little cropping this all is pure Pi.
This is called a colour-FA map:
Here we’re looking down from above at a slice about half way through the brain, so the top of the image is the front of the brain. The brightness of each pixel shows how directed the cabling is: bright means highly directed (like a pipe), dark means not directed at all (like a sponge). The colours indicate direction: red is left-right, green is up-down, and blue is into and out of the image. The bright bits are all major white matter structures in the brain, showing up clearly enough for them to be easily recognisable. I’ll point a few out as we go along.
Here’s a similar image but viewed from the front of the head. Again, this is about half way through the brain:
The blue structures here are called the Cortico-spinal tracts. They connect the areas of the brain controlling movement to the spinal cord and on to the muscles.
We can do more, though. Camino’s image viewer can show the tissue direction directly as well as the coloured FA map. This also runs on the Raspi (albeit a little slowly). Here’s an image of a couple of structures from the middle of the brain with tissue directions thrown in. The colours are as before, but now we’ve added some lines showing tissue direction at each point.
The green bits in the middle are part of the Cingulum, which connects the front and back of the brain and is involved in pain perception. The purple bits are part of the Corpus Callosum, which connects the two sides of the brain together and is involved in all sorts of things. It’s like a high-speed data connection that makes the brain more efficient. Here’s a close-up of another part of it, nearer the back of the brain, it’s the red/orangey bit that looks a like a moustache:
All this was pretty exciting, so I decided to try something a bit more complicated. DTI can only resolve one direction per voxel, so it has trouble with anything cross-shaped. There are a couple of more advanced techniques that can resolve more than one direction so I tried one of these. This is called Q-ball imaging. It needs to do a more complicated set of calculations than DTI and I wasn’t sure how well the Raspi would do with it. To my great delight it ran in about 15 minutes.
Q-ball also generates more information than DTI, and we can make more detailed images from the results. Here’s the output from Camino’s image generator for Q-ball:
The grey colours show directedness (but not direction), but if you look closely at the little coloured shapes in the full-size image you can see they look like little crosses, lines, and blobs. These are Q-ball’s way of describing directions and are coloured in the same way as before, with peaks in the main directions of the tissue.
At this point I really should admit that although the analysis ran in 15 minutes, generating that image so we could look at the results took over 2 hours. I hope you’ll agree it was worth the wait!
I was pretty impressed with how the Raspi performed. Research-level, mathematically complex code on a full-size dataset and it chewed through it in a few minutes. This is a system that you could use in Diffusion MRI research if you wanted to.
So why would you want to? Well, the Raspi is cheap and it uses very little power. This makes me think about using it in the developing world. Of course, in order to do MRI imaging you need an MRI scanner and these are not cheap but… recently some small, cheap MRI scanners that use the Earth’s magnetic field have recently been released. Using a Raspberry Pi to control one of these would allow you to acquire images as well as analyse the data and would make a very cheap complete MRI system that’s also easy to install and maintain – could be pretty handy. I’d love to get my hands on one of those to see if it would work with the Raspi!
Beyond that, the imaging I’ve done here is only the tip of the iceberg for diffusion imaging. Camino has a lot more tricks up its sleeve, although most of these are need a lot more computing power than what we’ve done here. But… there’s no reason why we have to process the data on piece at a time. We could have several Raspis working in parallel to speed things up (or using their GPUs), which would be very cool to try. In fact, using a dozen or more as a computing cluster would be a pretty chunky computing resource and only cost about as much as a single desktop PC.
All in all, a resounding success! If you’re interested in doing this yourself, everything I’ve used is available for free so there’s nothing stopping you from having a go. I’ll post more detailed instructions plus a full set of links soon.
Liz: and, faster than I could possibly have imagined, Matt’s got instructions and links ready to go. Enjoy!