[ITK Community] Image buffer pointer

Gib Bogle g.bogle at auckland.ac.nz
Mon Mar 17 00:24:48 EDT 2014


Hi,

I am doing manipulations on images by directly accessing the image buffer.  When I want to create a new image I currently employ a rather crude method.  I allocate a buffer of the right size, create the image in the buffer, then because I do not know how to make itk::Image use this buffer address I allocate the image buffer and copy from my buffer to the new image buffer:

         unsigned char *p_u8;

    typedef itk::Image<unsigned char,3> ImageType_u8;

    ImageType_u8::Pointer im_u8 = ImageType_u8::New();

    ImageType_u8::SizeType imsize;

    ImageType_u8::IndexType imstart;

    ImageType_u8::RegionType imregion;

    imsize[0] = width;

    imsize[1] = height;

    imsize[2] = depth;

    imstart[0] = 0;

    imstart[1] = 0;

    imstart[2] = 0;

    imregion.SetSize(imsize);

    imregion.SetIndex(imstart);

    im_u8->SetRegions(imregion);

    im_u8->Allocate();

    p_u8 = (unsigned char *)(im_u8->GetBufferPointer());

    // copy buffer to p_u8

    memcpy(p_u8,buffer,(size_t)(width*height*depth));

This works but is obviously inefficient.  Previously the inefficiency didn't bother me,
but now that I'm working with big tiff images I am running out of memory.  Is there a way to create an Image
and make it use a buffer that has already been allocated?

Thanks
Gib

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140317/39d180f4/attachment-0002.html>


More information about the Community mailing list