[Insight-users] Problem with ImportImageFilter

Harri Tapio Jaalinoja harri.jaalinoja@helsinki.fi
Mon, 11 Nov 2002 12:44:26 +0200 (EET)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--0-461582285-1037011466=:20163
Content-Type: TEXT/PLAIN; charset=US-ASCII


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



--0-461582285-1037011466=:20163
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="bitkShiftScale.cxx"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.OSF.4.30.0211111244260.20163@sirppi.helsinki.fi>
Content-Description: 
Content-Disposition: attachment; filename="bitkShiftScale.cxx"

Lyo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09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