[vtkusers] help for rendering a large amount of images
David Gobbi
david.gobbi at gmail.com
Fri Nov 6 11:34:23 EST 2015
Hi Henry,
A "flat file" is a file whose layout on disk is identical to the needed
layout of the data in memory. A flat file can be "memory mapped"
so that data in the file can be accessed via a C/C++ pointer, even
without loading the whole file into memory.
Memory mapping and flat files are not part of VTK, so you have
to create the flat file and memory-map it _before_ you pass the
memory pointer to VTK. For more information on memory mapping,
see e.g. https://en.wikipedia.org/wiki/Memory-mapped_file
As an example, here is how I use a flat file with VTK in Python,
in order to display a very large RGB image:
import mmap
import vtk
f = open("earth.21601x10801.bin","rb")
memory = mmap.mmap(f.fileno(),0,mmap.MAP_PRIVATE,mmap.PROT_READ)
importer = vtk.vtkImageImport()
importer.SetImportVoidPointer(memory)
importer.SetDataScalarTypeToUnsignedChar()
importer.SetNumberOfScalarComponents(3)
importer.SetDataExtent(0,21600,0,10800,0,0)
importer.SetWholeExtent(0,21600,0,10800,0,0)
importer.SetDataOrigin(0,0,0)
importer.SetDataSpacing(1,1,1)
reslice = vtkImageReslice()
reslice.SetInputConnection(importer.GetOutputPort())
# etcetera
The same concept can be used in C++, you just need to store your
entire data set as a huge flat file, use "mmap" (or an equivalent
function) to map the file to memory, and then use vtkImageImport
to allow the VTK pipeline to use the file as virtual memory.
My advice is to read as much as you can about memory mapping
and about how computers use virtual memory. This will be very
useful knowledge if you are using a computer with limited memory.
- David
On Fri, Nov 6, 2015 at 8:52 AM, Henry Blanco <henry.blanco at cbiomed.cu>
wrote:
> Hello David, thanks for your help and sorry for the late reply, I've
> been absent for a couple of days.
> Well we're newbies on vtk, ... therefore it would nice if you give us
> more details on:
> 1- How to create a flat file from several images. I guess we have to use
> some vtk classes, but we don't know which one.
> 2- How to achieve the mapping from the flat file memory address to the
> vtkImageData.
>
> Thanks in advance,
>
> Henry
>
> On mar, 2015-11-03 at 11:03 -0700, David Gobbi wrote:
> > Hi Henry,
> >
> >
> > Please reply to the vtk list, not just to me.
> >
> >
> > You're requirement of rendering "thousands of medical images" is
> > way too vague. Do you need to render them all simultaneously,
> > i.e. will they all be on screen at the same time? I really do not
> > understand what you are trying to do.
> >
> >
> > The vtkImageDataStreamer will be no help to you, because it always
> > loads the entire volume. It's job is to pull the data through the
> > pipeline
> > in small chunks, but the end result is still that the whole volume
> > ends
> > up in memory.
> >
> >
> > Yes, vtkImageReslice can show a sagittal or coronal view by only
> > streaming a small part of the volume into memory, but this will only
> > work with certain reader classes. For example, the vtkTIFFReader
> > always reads entire slices, so it cannot read just one row of a
> > slice that vtkImageReslice can then incorporate into a sagittal view.
> > In fact, I think that only vtkImageReader2 can stream individual
> > rows or columns of an image from disk. The other readers can
> > only stream the data slice-by-slice.
> >
> >
> > You should seriously consider my recommendation of using memory
> > mapping. If you simply map a flat file to a memory address and then
> > use that memory address as a pixel data inside a vtkImageData, then
> > the operating system can make all the decisions about how and when
> > to load the data from disk.
> >
> >
> > - David
> >
> >
> >
> > On Tue, Nov 3, 2015 at 10:33 AM, Henry Blanco
> > <henry.blanco at cbiomed.cu> wrote:
> > Thanks David for your soon reply. Ok, my problem is to load
> > and render thousands of medical images,
> > organized into series, by using VTK, but considering strong
> > limitations
> > in terms of RAM (e.g., only 128 or 256 MB of RAM available).
> >
> > To achieve this task, we have tried to use the
> > "vtkImageDataStreamer"
> > class, but we have failed. This class seems to load the whole
> > volume into
> > memory, therefore loading 2000 CT images (1GB) into memory may
> > fail if
> > we consider just 128 MB of RAM.
> >
> > We are thinking to partition the whole volume into K blocks
> > and to load
> > a block of images into memory just when it's needed. The
> > illusion of
> > having the whole volume loaded in memory could be achieved by
> > uploading/downloading one or more blocks of images to/from
> > memory when
> > needed. I'm wondering whether exist some vtk classes which can
> > be used
> > to picture a different view than the original (e.g., sagittal,
> > coronal,
> > or even oblique) without loading the whole volume of images.
> >
> > Henry
> >
> > On lun, 2015-11-02 at 17:29 -0700, David Gobbi wrote:
> > > What kind of views will you need? Do you just have to view
> > the
> > > original
> > > slices? If so, then the VTK pipeline's streaming will make
> > the job
> > > easy.
> > > If you need orthogonal or oblique views, things are more
> > difficult.
> > > Also,
> > > how is the data stored on disk? If the whole volume is
> > stored on disk
> > > as a single flat file, then you can memory map the file.
> > >
> > >
> > > - David
> > >
> > > On Mon, Nov 2, 2015 at 4:10 PM, Henry Blanco
> > <henry.blanco at cbiomed.cu>
> > > wrote:
> > > Hello guys, I need some hints on how to render a
> > large amount
> > > of images
> > > (e.g., thousands of images) using just few RAM
> > resources
> > > (e.g., 128 MB)
> > > using the vtkImageReslice class for the whole
> > volume.
> > >
> > > Thanks in advance
> > >
> > > Henry
> >
> >
> >
> >
> >
> >
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151106/cf288eea/attachment.html>
More information about the vtkusers
mailing list