<font size="2"><font face="verdana,sans-serif">Inside the convert procedure, your "output" 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->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->Graft(</span><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 16px; ">importFilter->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 "out", 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"><<a href="mailto:stefankoenig@gmail.com">stefankoenig@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br>
<br>
i've got a big problem, while i'm trying to convert picture data from<br>
raw data:<br>
<br>
i'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("C:\\Bilder\\Sonnenuntergang.jpg",<br>
(gimg));<br>
<br>
typedef itk::RGBPixel<unsigned char> Pixels;<br>
typedef itk::Image<Pixels, 2> RGBImage;<br>
<br>
RGBImage::Pointer img;<br>
void * pimg = &img;<br>
convertGILtoItkImage<Pixels>(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->SetImportPointer( localBuffer2, size[0]*size[1],<br>
importImageFilterWillOwnTheBuffer );<br>
importFilter->Update();<br>
<br>
*pimg = importFilter->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<ImageType> WriterType;<br>
WriterType::Pointer writer = WriterType::New();<br>
writer->SetFileName("C:\\checkWriteInMethod11.jpg");<br>
writer->SetInput(*pimg);<br>
try<br>
{<br>
writer->Write();<br>
}<br>
catch( itk::ExceptionObject & err )<br>
{<br>
qDebug() << "ExceptionObject caught !";<br>
qDebug() << err.what();<br>
}<br>
return pimg->GetPointer()->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'm getting a<br>
null pointer exception.<br>
<br>
but i'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>