0

I have 9 MRI images and would like to make a 3D volume out of these images. From there, I would like to interpolate in between each slice. Given two slices in the volume, I would like to create an intermediate frame in between that interpolates between the two slices. The goal is to create an 18 MRI volume that performs this interpolation.

How would I accomplish this in MATLAB?

rayryeng
  • 100,316
  • 21
  • 181
  • 185

1 Answers1

6

Assuming that your MRI images are in a 3D stacked volume, you can accomplish what you want by using interp3. The rows and columns of a slice will stay the same when choosing the sampling points, but the temporal or Z direction will simply double in size. So something like this, assuming that MRI is your volume:

[rows,cols,slices] = size(MRI);
[X,Y,Z] = meshgrid(1:cols, 1:rows, 1:slices);
[X2,Y2,Z2] = meshgrid(1:cols, 1:rows, 0.5:0.5:slices);
out = interp3(X, Y, Z, MRI, X2, Y2, Z2, 'linear', 0);

The above will generate a volume that has twice as many slices, keeping the rows and columns the same and using bilinear interpolation. The extra 0 ensures that if we are creating values that are outside of the original sampling points, we will extrapolate these points to 0.

If your images are not a 3D volume, you'll need to place this into a 3D matrix. Assuming that they're called MRI1 up to MRI9, you can do:

MRI = cat(3, MRI1, MRI2, MRI3, MRI4, MRI5, MRI6, MRI7, MRI8, MRI9);

You can then use the above code. Once you're finished, you can grab the intermediate slices by doing:

final_slices = MRI(:,:,1:2:end);

You can then access each intermediate slice with final_slices.


As a quick example seeing this working, let's assume that our volume is a bunch of random numbers in a 3 x 3 x 3 volume:

rng(123123);
MRI = rand(3,3,3)

MRI(:,:,1) =

    0.3002    0.8302    0.1768
    0.9946    0.7214    0.0678
    0.2901    0.4627    0.5201


MRI(:,:,2) =

    0.2323    0.8516    0.7838
    0.3251    0.5326    0.6377
    0.7220    0.4735    0.0717


MRI(:,:,3) =

    0.3202    0.1259    0.3360
    0.1004    0.9260    0.6287
    0.6922    0.3191    0.9011

Running the above interpolation code, we get:

out(:,:,1) =

     0     0     0
     0     0     0
     0     0     0


out(:,:,2) =

    0.3002    0.8302    0.1768
    0.9946    0.7214    0.0678
    0.2901    0.4627    0.5201


out(:,:,3) =

    0.2662    0.8409    0.4803
    0.6598    0.6270    0.3527
    0.5060    0.4681    0.2959


out(:,:,4) =

    0.2323    0.8516    0.7838
    0.3251    0.5326    0.6377
    0.7220    0.4735    0.0717


out(:,:,5) =

    0.2763    0.4887    0.5599
    0.2127    0.7293    0.6332
    0.7071    0.3963    0.4864


out(:,:,6) =

    0.3202    0.1259    0.3360
    0.1004    0.9260    0.6287
    0.6922    0.3191    0.9011

As you can see, the code certainly does create intermediate slices correctly. You see that every even position is one of the original MRI images, while the odd positions are the interpolated results. The first slice doesn't mean anything as we are trying to extrapolate from outside the known volume. You probably want to concentrate on the third slice and its odd positions after this point up until the end of the new volume.

rayryeng
  • 100,316
  • 21
  • 181
  • 185
  • thank you rayryeng,thanks alot I just hope it works – beautiful eyez Feb 23 '15 at 07:08
  • @beautifuleyez - No problem. Let me know if it does then get back to me. Thanks for accepting my answer btw! – rayryeng Feb 23 '15 at 07:08
  • I want to do 3D reconstruction of the brain tumor, uptill now I have found their boundaries and stacked them together on a 3D axis, I want to create a 3D volume of the whole using marching cubes algorithm.. can u guide me on this too – beautiful eyez Feb 23 '15 at 07:14
  • @beautifuleyez - I'm not familiar with the Marching Cubes algorithm. I don't know much about computer graphics unfortunately :(. However, for this particular interpolation, I know it works. I've updated my answer to show some example results. – rayryeng Feb 23 '15 at 07:16
  • thanks, but what other options do I have for 3D reconstruction of brain tumor using 2D MRI slices other than interpolation – beautiful eyez Feb 23 '15 at 07:31
  • @beautifuleyez - I unfortunately have no answer for you here. I'm not an expert in medical image processing. I certainly am an expert in image processing, but I have no medical background or expertise - only a basic familarity. I'm outside of my element here :(. Apologies again. Good luck though. – rayryeng Feb 23 '15 at 07:46
  • 1
    @beautifuleyez I think it's best if you ask a new question about that. Make sure it is specific and detailed enough. An [mcve](http://stackoverflow.com/help/mcve) would be good. – kkuilla Feb 23 '15 at 09:21
  • @rayryeng this code has some issue with out = interp3(X, Y, Z, MRI, X2, Y2, Z2, 'linear', 0); – beautiful eyez Feb 24 '15 at 06:13
  • please help me with that asap – beautiful eyez Feb 24 '15 at 06:14
  • Uh... yeah. Sure. *What* issue? I'm certainly not a mindreader, nor am I clairvoyant. If it's my job to guess what's wrong, I'm not playing this game. – rayryeng Feb 24 '15 at 06:14
  • @LuisMendo - Mentalist. – rayryeng Feb 24 '15 at 06:16
  • Im getting an error in it.. can u modify it,, or change it.. such that it works – beautiful eyez Feb 24 '15 at 06:20
  • 2
    Yeah **what error**? If you followed what I did above in my answer, you should be able to get it working. I even show an example of it working. Until you actually tell me what's wrong and what the error is, our conversation stops here. – rayryeng Feb 24 '15 at 06:20