[Insight-users] Problem with ImportImageFilter

Harri Tapio Jaalinoja harri.jaalinoja@helsinki.fi
Tue, 12 Nov 2002 13:02:04 +0200 (EET)


Thanks Bill,

this helped, the pixel prints out ok without segmentation fault.

However, later on in the code I try to write out the same image I read in,
and this only produces an empty file.

  // Set up the file writer
  ImageIOType::Pointer output_io = ImageIOType::New();
  output_io->SetByteOrderToLittleEndian();
  output_io->SetFileDimensionality(3);
  output_io->SetFileTypeToBinary();

  FileType::Pointer writer = FileType::New();
  writer->SetImageIO(output_io);
  outname = "ss_" + std::string(argv[1]) + ".raw";
  writer->SetFileName(outname.c_str());
  writer->SetInput(breader->GetOutput());
// //   writer->SetInput(ssfilter->GetOutput());

  try
    {
      writer->Write();
    }
  catch( itk::ExceptionObject & e )
    {
      message = "Exception caught during processing. \n";
      message += e.GetLocation();
      message += "\n";
      message += e.GetDescription();
      die(message);
    }

After the Update() call, breader->GetOutput() is ok, and it should give
the writer something to write, right?

[hajaalin@gene tmp]$ ls -l
total 65608
-rw-r--r--    1 hajaalin hajaalin 67109888 Nov 11 10:01 p3sh_222.mrc
-rw-r--r--    1 hajaalin hajaalin        0 Nov 12 12:53 ss_p3sh_222.mrc.raw

Any ideas?

Thanks!

Harri


On Mon, 11 Nov 2002, Lorensen, William E (Research) wrote:

> Harri,
> Try
> breader->Update()
>
> The GetOutput() method does not force a pipeline update.
>
> Bill
>
> -----Original Message-----
> From: Harri Tapio Jaalinoja [mailto:hajaalin@cc.helsinki.fi]
> Sent: Monday, November 11, 2002 5:44 AM
> To: insight-users@public.kitware.com
> Subject: [Insight-users] Problem with ImportImageFilter
>
>
>
> Hello all!
>
> I am using BSoft function to read in an image file. The function call
> gives me a struct with a pointer to the data.
>
>   Bimage* p = read_img(argv[1], 1, -1);
>
>   if(p->datatype != 7)
>     die("Only float data supported at the moment.");
>
>   typedef float PixelType;
>
>   PixelType* data = (PixelType *)p->data;
>   std::cerr << data[0] << std::endl;
>   std::cerr << data[9898345] << std::endl;
>   std::cerr << data[16777215] << std::endl;
>
>   unsigned long num = p->x * p->y * p->z;
>   std::cerr << num << std::endl;
>
> These values print out ok, so the reading part seems to be working.
> ---- output ----
> -0.160718
> -0.286178
> -0.160718
> 16777216
> ---- output ----
>
> Next I want to pass the data on to ITK, using either ImportImageFilter or
> ImportImageContainer.
>
>   itk::ImportImageFilter<PixelType, 3>::Pointer breader =
>     itk::ImportImageFilter<PixelType, 3>::New();
>   breader->SetImportPointer(data ,num, false);
>
> This does not work. I add
>   std::cerr << "Try to print a pixel from reader output..." << std::endl;
>   itk::Image<PixelType, 3>::Pointer image = breader->GetOutput();
>   std::cerr << image->GetPixel(index) << std::endl;
>   std::cerr << "OK" << std::endl;
>
> and get a segmentation fault. index points to pixel 9898345 (I tried
> {1,1,1}, too).
>
> ---- output ----
> Try to print a pixel from reader output...
> Segmentation fault
> ---- output ----
>
> To me this indicates that SetImportPointer did not do
> what I expected it to. What am I doing wrong?
>
> Thanks,
>
> Harri
>
>
>