4
$\begingroup$

I am looking to extract a large matrix from an InterpolatingFunction (roughly, 500x500x500), is there an easier way than extracting a Table ?

I want a matrix of the greyscale image data. Apologies for the lack of greyscale definition in the example I couldn't think how better to phrase it without attaching all my images. (my aim is to create a matrix of brain density from the greyscale data of scan slices.)

For example:

a = Import["ExampleData/CTengine.tiff", "Image3D"]
b = Image3DSlices[a];
c = Image3D[b, ColorFunction -> "Grayscale"];
d = ListInterpolation[ImageData[c]];

d[70, 70, 70]

0.133333

m =  ParallelTable[d[x, y, z], {x, 1, 10}, {y, 1, 10}, {z, 1, 10}] 

Seems to be a hefty run time ( AbsoluteTiming=25 for example above) , I'm sure there's a better way

Thanks

$\endgroup$
  • 2
    $\begingroup$ I think you need ArrayResample. For example, ArrayResample[ImageData[c], {10, 10, 10}] returns in less than a second on my machine. $\endgroup$ – Jason B. Apr 5 '18 at 21:14
  • $\begingroup$ @JasonB. Thanks! Perfect! Interesting function $\endgroup$ – Awkward Panda Apr 5 '18 at 21:46
1
$\begingroup$

Your ImageData[c] is a 3-dimensional array with dimensions {110, 256, 256}. To down-sample this to a {30,30,30} array, it's as easy as

ArrayResample[ImageData[c], {30, 30, 30}]

This is going to do the interpolation for you, but in a (hopefully) optimized way.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.