Get Teem at SourceForge.net. Fast, secure and Free Open Source software downloads
teem / unrrdu

  unu convert

unu convert: Convert nrrd to another type (as if by per-value cast). This
does not transform, scale, clamp, or intelligently quantize values; it just
copies them from one type to another, which replicates exactly what you'd get
in C when you assign from a variable of one type to another, or when you cast
to a differet type. See also "unu quantize","unu 2op x", and "unu 3op clamp".

Usage: unu convert -t <type> [-i <nin>] [-o <nout>]

-t <type> = type to convert to
 -i <nin> = input nrrd
-o <nout> = output nrrd (string); default: "-"
This makes available to nrrds the exact same rules of casting that apply to the basic scalar types in C. No attempt is made to clamp, scale, or otherwise map values. You can convert from and to any of the 10 scalar types.

One use for this is handling data that comes from a plain text file. Nrrd treats numerical data from plain text files as arrays of floats, so if you have a text file containing values which you know are integers, then unu convert is a simple way to convert them to an integral type after they've been read in. Here's some numbers in text.txt:

194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 0 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 0 194 194 194 194 194 194 194 194 0 194 194 194 194 194
194 194 194 194 0 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 0 194 0 0 0 194 194 194 0 0 194 194 194 194 194
194 194 194 194 0 0 194 194 194 0 194 194 194 0 194 194 194 194 194
194 194 194 194 0 194 194 194 194 0 194 194 194 0 194 194 194 194 194
194 194 194 194 0 194 194 194 194 0 194 194 194 0 194 194 194 194 194
194 194 194 194 0 194 194 194 194 0 194 194 194 0 194 194 194 194 194
194 194 194 194 0 194 194 194 194 0 194 0 0 0 0 0 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194 194
And this reads the text file to produce a PGM image:
unu convert -i text.txt -t uchar -o text.pgm