<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Indeed, Luis, that looks like just what I want!<br>
<br>
Thanks<br>
Gib<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF662292"><font color="#000000" size="2" face="Tahoma"><b>From:</b> Luis Ibanez [luis.ibanez@kitware.com]<br>
<b>Sent:</b> Monday, 17 March 2014 5:29 p.m.<br>
<b>To:</b> Gib Bogle<br>
<b>Cc:</b> community@itk.org<br>
<b>Subject:</b> Re: [ITK Community] Image buffer pointer<br>
</font><br>
</div>
<div></div>
<div>
<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" target="_blank">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" target="_blank">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" target="_blank">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>
</div>
</div>
</div>
</body>
</html>