[ITK Community] Image buffer pointer
Gib Bogle
g.bogle at auckland.ac.nz
Mon Mar 17 06:01:51 EDT 2014
Well, obviously this was the problem. Initially I was working with a separate allocated buffer, then to save memory I started modifying the image "in place". I was slow to realize that this actually makes the image writing very simple - I just need
writer->SetInput(im_u8);
I have learned something useful about itk::ImportImageFilter anyway. :)
Gib
________________________________
From: Community [community-bounces at itk.org] on behalf of Gib Bogle [g.bogle at auckland.ac.nz]
Sent: Monday, 17 March 2014 10:44 p.m.
To: Luis Ibanez
Cc: community at itk.org
Subject: Re: [ITK Community] Image buffer pointer
Hi Luis,
I implemented this method, and it works. But there is a problem. When I exit the program I get this:
The program has unexpectedly finished.
E:\LN_structure\vessel-tools\Qt\equaliser-build\equaliser.exe exited with code -1073741819
The output file was written successfully, but somehow the program (perhaps the stack) is left in a bad state. Could it be a problem that buffer in this statement
importFilter->SetImportPointer( buffer, numberOfPixels, importImageFilterWillOwnTheBuffer );
is this:
buffer = (unsigned char *)(im_u8->GetBufferPointer());
where im_u8 is an image that I previously read in?
________________________________
From: Luis Ibanez [luis.ibanez at kitware.com]
Sent: Monday, 17 March 2014 5:29 p.m.
To: Gib Bogle
Cc: community at itk.org
Subject: Re: [ITK Community] Image buffer pointer
Gib
The itkImportImageFilter
http://www.itk.org/Wiki/ITK/Examples/IO/ImportImageFilter
Might be what you are looking for.
Hope this helps
Luis
On Mar 17, 2014 12:24 AM, "Gib Bogle" <g.bogle at auckland.ac.nz<mailto:g.bogle at auckland.ac.nz>> wrote:
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
_______________________________________________
Community mailing list
Community at itk.org<mailto:Community at itk.org>
http://public.kitware.com/cgi-bin/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140317/77b755af/attachment-0002.html>
More information about the Community
mailing list