<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;">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=" color:#000000;">*</span><span style=" color:#000000;">p_u8</span><span style=" color:#000000;">;</span>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; 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=" color:#000000;">::</span><span style=" color:#800080;">Image</span><span style=" color:#000000;"><</span><span style=" color:#808000;">unsigned</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">char</span><span style=" color:#000000;">,</span><span style=" color:#000080;">3</span><span style=" color:#000000;">></span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">ImageType_u8</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">ImageType_u8</span><span style=" color:#000000;">::</span><span style=" color:#800080;">Pointer</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">im_u8</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">ImageType_u8</span><span style=" color:#000000;">::</span>New<span style=" color:#000000;">();</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">ImageType_u8</span><span style=" color:#000000;">::</span><span style=" color:#800080;">SizeType</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">imsize</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">ImageType_u8</span><span style=" color:#000000;">::</span><span style=" color:#800080;">IndexType</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">imstart</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">ImageType_u8</span><span style=" color:#000000;">::</span><span style=" color:#800080;">RegionType</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">imregion</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imsize</span><span style=" color:#000000;">[</span><span style=" color:#000080;">0</span><span style=" color:#000000;">]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">width</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imsize</span><span style=" color:#000000;">[</span><span style=" color:#000080;">1</span><span style=" color:#000000;">]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">height</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imsize</span><span style=" color:#000000;">[</span><span style=" color:#000080;">2</span><span style=" color:#000000;">]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">depth</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imstart</span><span style=" color:#000000;">[</span><span style=" color:#000080;">0</span><span style=" color:#000000;">]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imstart</span><span style=" color:#000000;">[</span><span style=" color:#000080;">1</span><span style=" color:#000000;">]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imstart</span><span style=" color:#000000;">[</span><span style=" color:#000080;">2</span><span style=" color:#000000;">]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span><span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imregion</span><span style=" color:#000000;">.</span>SetSize<span style=" color:#000000;">(</span><span style=" color:#000000;">imsize</span><span style=" color:#000000;">);</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">imregion</span><span style=" color:#000000;">.</span>SetIndex<span style=" color:#000000;">(</span><span style=" color:#000000;">imstart</span><span style=" color:#000000;">);</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">im_u8</span><span style=" color:#000000;">-></span>SetRegions<span style=" color:#000000;">(</span><span style=" color:#000000;">imregion</span><span style=" color:#000000;">);</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">im_u8</span><span style=" color:#000000;">-></span>Allocate<span style=" color:#000000;">();</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000000;">p_u8</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">(</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=" color:#000000;">*)(</span><span style=" color:#000000;">im_u8</span><span style=" color:#000000;">-></span>GetBufferPointer<span style=" color:#000000;">());</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; 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; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span>memcpy<span style=" color:#000000;">(</span><span style=" color:#000000;">p_u8</span><span style=" color:#000000;">,</span><span style=" color:#000000;">buffer</span><span style=" color:#000000;">,(</span><span style=" color:#800080;">size_t</span><span style=" color:#000000;">)(</span><span style=" color:#800000;">width</span><span style=" color:#000000;">*</span><span style=" color:#800000;">height</span><span style=" color:#000000;">*</span><span style=" color:#800000;">depth</span><span style=" color:#000000;">));</span></pre>
<pre style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; 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>
</body>
</html>