Render a single slice from a stack without reading the full stack into memory


I have a dataset of 1000 images, with a total size of 11 GB. In my application, I want to render a specific slice in the window based on interactive user input. I’d like to do this in a way that does not involve reading the full stack into memory.

So far, I’ve been using the PNG reader and providing the path to the folder with individual 2D PNG files. The code provided below works, but I would eventually want to work with multi-page tiff stacks, so that the data handling is easier (moving one file around vs. moving several hundred). I could create stacks in the .ome.tif format with about 300 images in each file. I tried replicating the code with vtkTIFFReader and providing the filename of the stack, but that still reads in the full stack into memory.

Any help would be appreciated.


        imagePNGReader = vtk.vtkPNGReader()
		imagePNGReader.SetFilePrefix(folderImagesPath + '\\') 
		imagePNGReader.SetDataExtent(0, self.extent_x, 0, self.extent_y, 0, self.extent_z)
		imagePNGReader.SetDataSpacing(pixel_size_xy, pixel_size_xy, thickness)

		self.imageXY = vtk.vtkExtractVOI()
		self.imageXY.SetVOI(0, self.extent_x, 0, self.extent_y, 0, 0)

		# Create a greyscale lookup table
		table = vtk.vtkLookupTable()
		table.SetRange(0, 255) 
		table.SetValueRange(0.0, 1.0) 
		table.SetSaturationRange(0.0, 0.0) 

		# Map the image through the lookup table
		xy_color = vtk.vtkImageMapToColors()
		self.XYSliceActor = vtk.vtkImageActor()
		self.XYSliceActor.SetPosition(0, 0, 0)

Some VTK IP classes may support streaming reading, but probably you would be better off using dask/zarr/xarray, as you get sophisticated tiling, caching, resampling for free. See a simple example here. I guess you can also learn management of large images from ParaView. MSVTK could be very relevant, too, but I think that project was discontinued.