[Insight-users] Problem with ImportImageFilter

Lorensen, William E (Research) lorensen@crd.ge.com
Mon, 11 Nov 2002 08:04:23 -0500


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