[Insight-users] Problems creating image from raw data
Dženan Zukić
dzenanz at gmail.com
Wed Jul 27 10:46:47 EDT 2011
Inside the convert procedure, your "output" image is just a procedure-local
copy of the image structure.
Instead of this:
*pimg = importFilter->GetOutput();
You should do something like this:
pimg->Graft(importFilter->GetOutput());
A simple example of what you were doing is:
void square(int in, int out)
{
out=in*in;
}
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.
2011/7/27 Stefan König <stefankoenig at gmail.com>
> Hello,
>
> i've got a big problem, while i'm trying to convert picture data from
> raw data:
>
> i'm doing it, way if found in this mailing list, but it wont work for
> me, allways getting a null pointer exception.
>
> thats the way i tried:
>
> boost::gil::rgb8_image_t gimg(800,600);
>
> boost::gil::jpeg_read_and_convert_image("C:\\Bilder\\Sonnenuntergang.jpg",
> (gimg));
>
> typedef itk::RGBPixel<unsigned char> Pixels;
> typedef itk::Image<Pixels, 2> RGBImage;
>
> RGBImage::Pointer img;
> void * pimg = &img;
> convertGILtoItkImage<Pixels>(gimg, pimg);
>
>
> and now, what im doing in convertGILtoItkImage(..)
>
> dstPixelType *localBuffer = (dstPixelType*) data;
>
> int bythelength = width*height*numChannels;
> dstPixelType * localBuffer2 = new dstPixelType[ width*height ];
>
> // copy buffer from gil image to new buffer, which will be owned by
> itk
> image
> memcpy(localBuffer2, localBuffer, bythelength);
>
> // if set to true, itk will do memory managment
> const bool importImageFilterWillOwnTheBuffer = true;
> importFilter->SetImportPointer( localBuffer2, size[0]*size[1],
> importImageFilterWillOwnTheBuffer );
> importFilter->Update();
>
> *pimg = importFilter->GetOutput();
>
>
> // hier geht alles, bild ist vorhanden wir geschrieben... kimg
> bekommt
> irgendwoher nen desktruktoraufruf der alles kaputt macht :(
> typedef itk::ImageFileWriter<ImageType> WriterType;
> WriterType::Pointer writer = WriterType::New();
> writer->SetFileName("C:\\checkWriteInMethod11.jpg");
> writer->SetInput(*pimg);
> try
> {
> writer->Write();
> }
> catch( itk::ExceptionObject & err )
> {
> qDebug() << "ExceptionObject caught !";
> qDebug() << err.what();
> }
> return pimg->GetPointer()->Register();
> ---------------------------------------------------------
>
> if i write out my picture inside the conversion method, everything works
> fine, but if i try to write it out it outside the method, i'm getting a
> null pointer exception.
>
> but i've no idea why?
>
> can somebody help me?
>
> regards
> Stefan
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110727/891c4784/attachment.htm>
More information about the Insight-users
mailing list