ImageSlicing operation error

(Tomonari Hayakawa ) #1

I have run the ImageSlicing sample.
However, the following error was displayed.
vtk_error
I understand that it is a vtkImageReader2 error, but I don’t know how to cope.
please tell me.

(David Gobbi) #2

Maybe the file is smaller than expected. For example,

reader->SetDataExtent(0, 63, 0, 63, 1, 93);
reader->SetDataScalarTypeToUnsignedShort();

This means each slice is 64*64 pixels, and each pixel is 2 bytes.
So each file (quarter.1, quarter.2 … quarter.93) must be 8192 bytes.

Here is another example:

reader->SetDataExtent(0, 511, 0, 511, 0, 191);
reader->SetDataScalarTypeToUnsignedChar();
reader->SetFileDimensionality(3):

This expects one file that is 512*512*192*1 bytes, or 50331648 bytes.

1 Like
(Tomonari Hayakawa ) #3

Thank you for your reply and the detailed explanation.
I could understand the example.

What kind of correction do you need in this case?

(David Gobbi) #4

To use vtkImageReader2,

  • The file must be a raw image (the file must not have a header)
  • The data type of the pixels must be known (short, unsigned short, unsigned char)
  • The dimensionality of the file must be known (2D or 3D)
  • The dimensions of the file must be known (Xsize, Ysize) or (Xsize, Ysize, Zsize)

Then the reader must be set up correctly. For 2D files:

reader->SetDataExtent(0, Xsize-1, 0, Ysize-1, 1, NumberOfFiles);
reader->SetDataScalarTypeToUnsignedShort(); // or Short or UnsignedChar etc.
reader->SetFileDimensionality(2); // 2D is the default, so this is optional
reader->SetFilePrefix(...); // or SetFileNames(), please see class documentation

For 3D files:

reader->SetDataExtent(0, Xsize-1, 0, Ysize-1, 0, Zsize-1);
reader->SetDataScalarTypeTo...(); // same as 2D example
reader->SetFileDimensionality(3);
reader->SetFileName(...); // path to the file
(Tomonari Hayakawa ) #5

Thank you for your reply.
In your explanation, I was able to learn more about vtkImageReader2.
I was able to output the raw data (3D) I have.

I want to output an oblique tomographic image by specifying an angle in the future.
I think to add data rotation as follows.
//Data rotation
vtkSmartPointer transform =
vtkSmartPointer ::New();
transform-> RotateY (90);
transform-> RotateZ (0);

Please tell me if you know how to add it.