<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}
-->
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;">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<br>
<br>
<span style=" color:#c0c0c0;"></span><span style=" color:#000000;">writer</span><span style=" color:#000000;">-></span>SetInput<span style=" color:#000000;">(</span><span style=" color:#800000;">im_u8</span><span style=" color:#000000;">);</span>
<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></pre>
I have learned something useful about <span style=" color:#800080;">itk</span><span style=" color:#000000;">::</span><span style=" color:#800080;">ImportImageFilter anyway. :)<br>
Gib<br>
</span>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF12263"><font color="#000000" size="2" face="Tahoma"><b>From:</b> Community [community-bounces@itk.org] on behalf of Gib Bogle [g.bogle@auckland.ac.nz]<br>
<b>Sent:</b> Monday, 17 March 2014 10:44 p.m.<br>
<b>To:</b> Luis Ibanez<br>
<b>Cc:</b> community@itk.org<br>
<b>Subject:</b> Re: [ITK Community] Image buffer pointer<br>
</font><br>
</div>
<div></div>
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Hi Luis,<br>
<br>
I implemented this method, and it works.  But there is a problem.  When I exit the program I get this:<br>
<br>
<span style="font-family:'Courier'; font-size:10pt; font-weight:600; color:#aa0000">The program has unexpectedly finished.</span>
<p style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px">
<span style="font-family:'Courier'; font-size:10pt; font-weight:600; color:#0000aa">E:\LN_structure\vessel-tools\Qt\equaliser-build\equaliser.exe exited with code -1073741819</span></p>
<br>
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<br>
<br>
<span style="color:#c0c0c0"></span><span style="color:#000000">importFilter</span><span style="color:#000000">-></span>SetImportPointer<span style="color:#000000">(</span><span style="color:#c0c0c0">
</span><span style="color:#000000">buffer</span><span style="color:#000000">,</span><span style="color:#c0c0c0">
</span><span style="color:#000000">numberOfPixels</span><span style="color:#000000">,</span><span style="color:#c0c0c0">
</span><span style="color:#000000">importImageFilterWillOwnTheBuffer</span><span style="color:#c0c0c0">
</span><span style="color:#000000">);</span>
<pre style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px"><br><font face="Tahoma">is this</font>:<br><br><span style="color:#c0c0c0"></span><span style="color:#800000">buffer</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:#800000">im_u8</span><span style="color:#000000">-></span>GetBufferPointer<span style="color:#000000">());</span><br><br><font face="Tahoma">where im_u8 is an image that I previously read in?</font> <br><pre style="margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px"><br></pre><br></pre>
<br>
<div style="font-family:Times New Roman; color:#000000; font-size:16px">
<hr tabindex="-1">
<div id="divRpF36679" style="direction:ltr"><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>
</div>
</div>
</div>
</body>
</html>