<p dir="ltr">Gib</p>
<p dir="ltr">The itkImportImageFilter</p>
<p dir="ltr"><a href="http://www.itk.org/Wiki/ITK/Examples/IO/ImportImageFilter">http://www.itk.org/Wiki/ITK/Examples/IO/ImportImageFilter</a></p>
<p dir="ltr">Might be what you are looking for.</p>
<p dir="ltr">Hope this helps</p>
<p dir="ltr">   Luis<br>
</p>
<div class="gmail_quote">On Mar 17, 2014 12:24 AM, "Gib Bogle" <<a href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div>
<div style="direction:ltr;font-size:10pt;font-family:Tahoma">Hi,<br>
<br>
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:<br>
<br>
<span style="color:#c0c0c0">         </span><span style="color:#808000">unsigned</span><span style="color:#c0c0c0">
</span><span style="color:#808000">char</span><span style="color:#c0c0c0"> </span>
<span style>*</span><span style>p_u8</span><span style>;</span>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style="color:#808000">typedef</span><span style="color:#c0c0c0"> </span><span style="color:#800080">itk</span><span style>::</span><span style="color:#800080">Image</span><span style><</span><span style="color:#808000">unsigned</span><span style="color:#c0c0c0"> </span><span style="color:#808000">char</span><span style>,</span><span style="color:#000080">3</span><span style>></span><span style="color:#c0c0c0"> </span><span style="color:#800080">ImageType_u8</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">ImageType_u8</span><span style>::</span><span style="color:#800080">Pointer</span><span style="color:#c0c0c0"> </span><span style>im_u8</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#800080">ImageType_u8</span><span style>::</span>New<span style>();</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">ImageType_u8</span><span style>::</span><span style="color:#800080">SizeType</span><span style="color:#c0c0c0"> </span><span style>imsize</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">ImageType_u8</span><span style>::</span><span style="color:#800080">IndexType</span><span style="color:#c0c0c0"> </span><span style>imstart</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">ImageType_u8</span><span style>::</span><span style="color:#800080">RegionType</span><span style="color:#c0c0c0"> </span><span style>imregion</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imsize</span><span style>[</span><span style="color:#000080">0</span><span style>]</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#800000">width</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imsize</span><span style>[</span><span style="color:#000080">1</span><span style>]</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#800000">height</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imsize</span><span style>[</span><span style="color:#000080">2</span><span style>]</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#800000">depth</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imstart</span><span style>[</span><span style="color:#000080">0</span><span style>]</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#000080">0</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imstart</span><span style>[</span><span style="color:#000080">1</span><span style>]</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#000080">0</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imstart</span><span style>[</span><span style="color:#000080">2</span><span style>]</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style="color:#000080">0</span><span style>;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imregion</span><span style>.</span>SetSize<span style>(</span><span style>imsize</span><span style>);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>imregion</span><span style>.</span>SetIndex<span style>(</span><span style>imstart</span><span style>);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>im_u8</span><span style>-></span>SetRegions<span style>(</span><span style>imregion</span><span style>);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>im_u8</span><span style>-></span>Allocate<span style>();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style>p_u8</span><span style="color:#c0c0c0"> </span><span style>=</span><span style="color:#c0c0c0"> </span><span style>(</span><span style="color:#808000">unsigned</span><span style="color:#c0c0c0"> </span><span style="color:#808000">char</span><span style="color:#c0c0c0"> </span><span style>*)(</span><span style>im_u8</span><span style>-></span>GetBufferPointer<span style>());</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span><span style="color:#008000">//</span><span style="color:#c0c0c0"> </span><span style="color:#008000">copy</span><span style="color:#c0c0c0"> </span><span style="color:#008000">buffer</span><span style="color:#c0c0c0"> </span><span style="color:#008000">to</span><span style="color:#c0c0c0"> </span><span style="color:#008000">p_u8</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="color:#c0c0c0">    </span>memcpy<span style>(</span><span style>p_u8</span><span style>,</span><span style>buffer</span><span style>,(</span><span style="color:#800080">size_t</span><span style>)(</span><span style="color:#800000">width</span><span style>*</span><span style="color:#800000">height</span><span style>*</span><span style="color:#800000">depth</span><span style>));</span></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br>This works but is obviously inefficient.  Previously the inefficiency didn't bother me, <br>but now that I'm working with big tiff images I am running out of memory.  Is there a way to create an Image <br>
and make it use a buffer that has already been allocated?<br><br>Thanks<br>Gib<br></pre>
<br>
</div>
</div>

<br>_______________________________________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org">Community@itk.org</a><br>
<a href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
<br></blockquote></div>