pythonperformanceimage-processingmemory-management

Is there a more efficient way to get "x-z" slices from a stack of "x-y" images?


I have a CT scan of an object: images with pixels in an x-y grid, one image per z value.

I want to make x-z images, to view the object from a different angle.

The most obvious way to do this: load all the images into a 3D array like bigImageArray[x,y,z] and save the slices bigImageArray[:,y,:] for each value of y.

The problem: bigImageArray would be too large to store in memory.

What's the best way to handle this?

Attempted solution: for each y value, make an empty x-z array, open each x-y image and fill in one line.

This works but is quite slow (lots of file opening/closing).

Adding a python tag since that's what I've been using, but I'm open to using anything


Solution

  • let's say you can fit n x-y or n x-z images into memory.

    Load up n x-y images and use them to write out n width x n x n "blocks". Repeat until you've covered z.

    Then, load up all the blocks that have y=0, and use them to write out n x-z images. Repeat until you've covered y.