<font size="2"><font face="verdana,sans-serif">Inside the convert procedure, your &quot;output&quot; image is just a procedure-local copy of the image structure.<br></font></font><div><font class="Apple-style-span" face="verdana, sans-serif"><br>

</font></div><div><font class="Apple-style-span" face="verdana, sans-serif">Instead of this:</font></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 16px; "> *pimg = importFilter-&gt;GetOutput();</span></div>

<div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 16px; ">You should do something like this:</span></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 16px; ">pimg-&gt;Graft(</span><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 16px; ">importFilter-&gt;GetOutput());</span></div>

<div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 16px; "><br></span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;">A simple example of what you were doing is:</span></font></div>

<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;">void square(int in, int out)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;">{</span></font></div>

<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;">  out=in*in;</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;">}</span></font></div>

<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;">And when the function is called a value is copied to local parameter &quot;out&quot;, and whatever you do with it is not reflected on the original variable.</span></font></div>

<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 16px;"><br></span></font><div class="gmail_quote">2011/7/27 Stefan König <span dir="ltr">&lt;<a href="mailto:stefankoenig@gmail.com">stefankoenig@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br>
<br>
i&#39;ve got a big problem, while i&#39;m trying to convert picture data from<br>
raw data:<br>
<br>
i&#39;m doing it, way if found in this mailing list, but it wont work for<br>
me, allways getting a null pointer exception.<br>
<br>
thats the way i tried:<br>
<br>
        boost::gil::rgb8_image_t gimg(800,600);<br>
        boost::gil::jpeg_read_and_convert_image(&quot;C:\\Bilder\\Sonnenuntergang.jpg&quot;,<br>
(gimg));<br>
<br>
        typedef itk::RGBPixel&lt;unsigned char&gt; Pixels;<br>
        typedef itk::Image&lt;Pixels, 2&gt; RGBImage;<br>
<br>
   RGBImage::Pointer img;<br>
   void * pimg = &amp;img;<br>
   convertGILtoItkImage&lt;Pixels&gt;(gimg, pimg);<br>
<br>
<br>
and now, what im doing in convertGILtoItkImage(..)<br>
<br>
        dstPixelType *localBuffer = (dstPixelType*) data;<br>
<br>
        int bythelength = width*height*numChannels;<br>
        dstPixelType * localBuffer2 = new dstPixelType[ width*height ];<br>
<br>
        // copy buffer from gil image to new buffer, which will be owned by itk<br>
image<br>
        memcpy(localBuffer2, localBuffer, bythelength);<br>
<br>
        // if set to true, itk will do memory managment<br>
        const bool importImageFilterWillOwnTheBuffer = true;<br>
        importFilter-&gt;SetImportPointer( localBuffer2, size[0]*size[1],<br>
importImageFilterWillOwnTheBuffer );<br>
        importFilter-&gt;Update();<br>
<br>
        *pimg = importFilter-&gt;GetOutput();<br>
<br>
<br>
        // hier geht alles, bild ist vorhanden wir geschrieben... kimg bekommt<br>
irgendwoher nen desktruktoraufruf der alles kaputt macht :(<br>
        typedef itk::ImageFileWriter&lt;ImageType&gt;  WriterType;<br>
        WriterType::Pointer writer = WriterType::New();<br>
        writer-&gt;SetFileName(&quot;C:\\checkWriteInMethod11.jpg&quot;);<br>
        writer-&gt;SetInput(*pimg);<br>
        try<br>
        {<br>
                writer-&gt;Write();<br>
        }<br>
        catch( itk::ExceptionObject &amp; err )<br>
        {<br>
                qDebug() &lt;&lt; &quot;ExceptionObject caught !&quot;;<br>
                qDebug() &lt;&lt; err.what();<br>
        }<br>
        return  pimg-&gt;GetPointer()-&gt;Register();<br>
---------------------------------------------------------<br>
<br>
if i write out my picture inside the conversion method, everything works<br>
fine, but if i try to write it out it outside the method, i&#39;m getting a<br>
null pointer exception.<br>
<br>
but i&#39;ve no idea why?<br>
<br>
can somebody help me?<br>
<br>
regards<br>
Stefan<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div>