Is there anyway to read in vtk files and determine the value of each pixel?

TheKidd88's Avatar, Join Date: Jun 2007
Light Poster
Cause I need to figure out how to do that.
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Yep. You learn what the format is, what the parts of it mean, and read the file accordingly. For instance, there is usually a small piece which describes the type of format, and its version. Then there's a header that describes the data. For instance, is it color or grayscale. How many bytes per pixel? Is there a color table or are the pixels raw color data. Stuff like that.

Personally, I study the format. Then I define some structures or classes that conform to the various pieces of the format (magic number, version, header, etc.). Then I write the code to read the file into those structures, then I refer to the information in those structures when reading the raw data.
TheKidd88's Avatar, Join Date: Jun 2007
Light Poster
I don't understand what you are saying. This is the header of the files:
# vtk DataFile Version 3.0
VTK File Generated by Insight Segmentation and Registration Toolkit (ITK)
BINARY
DATASET STRUCTURED_POINTS
DIMENSIONS 41 41 41
SPACING 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00
ORIGIN 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
POINT_DATA 68921
SCALARS scalars unsigned_char 1
LOOKUP_TABLE default

What I want to do is be able to read in the vtk file and then read in the value of each pixel. Starting with the pixel located at 0 0 0, all the way to the pixel located at 41 41 41.
DaWei's Avatar, Join Date: Dec 2006
Team Leader
What part of that don't you understand? Here is an example definition from a VTK spec:
Quote:
The legacy VTK file formats consist of five basic parts.

1. The first part is the file version and identifier. This part contains the single line: # vtk DataFile Version x.x.
This line must be exactly as shown with the exception of the version number x.x, which will vary with different
releases of VTK. (Note: the current version number is 3.0. Version 1.0 and 2.0 files are compatible with version 3.0
files.)

2. The second part is the header. The header consists of a character string terminated by end-of-line character \n. The
header is 256 characters maximum. The header can be used to describe the data and include any other pertinent
information.

3. The next part is the file format. The file format describes the type of file, either ASCII or binary. On this line the single
word ASCII or BINARY must appear.

4. The fourth part is the dataset structure. The geometry part describes the geometry and topology of the dataset. This
part begins with a line containing the keyword DATASET followed by a keyword describing the type of dataset.
Then, depending upon the type of dataset, other keyword/data combinations define the actual data.

5. The final part describes the dataset attributes. This part begins with the keywords POINT_DATA or CELL_DATA, followed
by an integer number specifying the number of points or cells, respectively. (It doesn’t matter whether
POINT_DATA or CELL_DATA comes first.) Other keyword/data combinations then define the actual dataset attribute
values (i.e., scalars, vectors, tensors, normals, texture coordinates, or field data).
Now, if you look at that, and you look at your own post, does the picture begin to clarify for you? Incidentally, do you know how to write a program using the C or C++ languages?