[vtkusers] Setting grayscale range for binary image file

dfcsingh at sri.utoronto.ca dfcsingh at sri.utoronto.ca
Wed Sep 18 12:17:12 EDT 2013


Hi,

This is probably a trivial question for this mailing list but I couldn't
find a solution online.
My overall goal is to write a method to display the Varian MRI image type
FDF (Flexible Data File) using vtk. As far as I can tell FDF consists of a
simple plain text header followed by binary image data.
I found a Matlab script that displays FDF's and am using it as a guide
line to write my vtk program. Essentially the script parses the header and
finds the data type (32 bit float), the machine type (little endian) and
the matrix size (256,256). It then strips the header and sends the
remaining data to Matlab's imshow method as follows.

figure;
imshow(img, [])
colormap(gray);
axis image;
axis off;

I've manually stripped the header and am sending the resulting file to
vtkImageReader2 as follows:
  vtkSmartPointer<vtkImageReader2> reader=
vtkSmartPointer<vtkImageReader2>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->SetDataExtent(0, 255, 0, 255, 1, 255);
  reader->SetDataScalarTypeToFloat();
  reader->SetDataByteOrderToLittleEndian();
  reader->UpdateWholeExtent();

This results in a black rendered image where as the Matlab script gives
the proper grayscale MRI image. The only difference I can figure out is
the imshow(img,[]) command scales the values so that the max value in the
FDF file (around 0.01) is black and the min value (0) is white. Is this
necessary in vtk (and if so how do I accomplish this) or should the
vtkImageReader2 handle this automatically?

Thanks for any help you can give and this is my first time posting to the
mailing list so please advise if I can do anything better next time!

-David




More information about the vtkusers mailing list