[Insight-users] itkImageSource for block of memory

Bill Lorensen bill.lorensen at gmail.com
Fri Jun 19 08:11:11 EDT 2009


Yes, you have to careful. Accessing the buffer directly is generally
not advised. If you don't mind making a copy of the image, then you
should use an iterator.

Currently, the memory is contiguous. I would expect that if we add
containers in the future that have non-contiguous memory layout that
we will provide a mechanism to determine the memory layout.

Also, by default, the memory will be released when the image is
destroyed. You can tell the image's container to prevent the
destructor from releasing the memory with
image->GetPIxelContainer()->ContainerManageMemoryOff();

This should be done after the Update that produces the image. Also,
you will be responsible to free the memory.

On Fri, Jun 19, 2009 at 8:01 AM, Koen Vermeer<koen at vermeer.tv> wrote:
> On Fri, 2009-06-19 at 07:53 -0400, Bill Lorensen wrote:
>> You can get a pointer to an image's pixel buffer with image->GetBufferPointer().
>
> Hmm, that's probably what I wouldn't have done if I hadn't read any
> manuals. It seems that accessing the buffer is generally not advised;
> instead, iterators are often suggested when processing larger areas,
> while SetPixel/GetPixel is used for individual pixels.
>
> Can I safely assume that the image's pixel buffer is just a continuous
> area of memory that contains the image data in the expected order?
>
> Also: How do I make sure the buffer isn't freed when the image is
> destroyed?
>
> Koen
>
>


More information about the Insight-users mailing list