[Insight-users] Problems creating image from raw data

Stefan1 Koenig stefan1.koenig at stud.fh-regensburg.de
Wed Jul 27 08:31:21 EDT 2011


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


More information about the Insight-users mailing list