View source: R/write_dti_tracks.R
| write.dti.tsf | R Documentation |
The TSF format stores one scalar value per point of a streamline, e.g., the fractional anisotropy, the distance along the track or a value sampled from an image at the point coordinates. It is the companion format of the TCK format: a TSF file contains no coordinates and no track boundaries, it is just a stream of values that has to be read together with the tractogram it describes. The number of values per track is therefore required to write the file, and a TSF file without the matching TCK file is meaningless to every reader (MRtrix checks this, see the note below).
write.dti.tsf(
tracts,
filepath,
lengths = NULL,
datatype = "Float32LE",
gzip = NULL,
header = list()
)
tracts |
the values to write. This can be an |
filepath |
character string, the path of the file to write. |
lengths |
integer vector or NULL, the number of values per track. This
is ignored unless |
datatype |
character string, one of 'Float32LE' (the default, and what MRtrix writes), 'Float32BE', 'Float64LE' or 'Float64BE'. |
gzip |
logical or NULL, whether to gzip-compress the output. If
|
header |
named list of additional header entries to store in the file, e.g., the header of the file the tracks were read from. The entries 'id', 'datatype', 'count', 'file' and 'derived' are always computed by the readers and cannot be set. |
the file path, invisibly.
The TSF format stores a NaN value after every track, and unlike the TCK
format it has no Inf terminator: the reader relies on the delimiters to
split the value stream into tracks. A file whose values are not delimited
exactly like the tracks of the tractogram can therefore not be detected as
broken by this package, but MRtrix reports the mismatch of the track counts
when the file is used (e.g., in tcksample or tsfvalidate).
read.dti.tsf, write.dti.tck
# A TSF file stores one value per point. Since the format contains no track
# boundaries, the track lengths have to be provided:
tsff <- tempfile(fileext = ".tsf");
values_by_track <- list(c(0.1, 0.2, 0.3), c(0.4, 0.5));
write.dti.tsf(values_by_track, tsff);
read.dti.tsf(tsff)$scalars$scalar_list;
# The same file can be written from one vector of values and the lengths:
write.dti.tsf(c(0.1, 0.2, 0.3, 0.4, 0.5), tsff, lengths = c(3L, 2L));
## Not run:
# Read the values of a track scalar file, modify them and write them back:
tsf <- read.dti.tsf("brain.tsf");
tsf$scalars$merged <- tsf$scalars$merged * 2;
write.dti.tsf(tsf$scalars, "brain_doubled.tsf");
# Sample an image along the tracks of a tractogram and store the result. The
# values of a TRK file that has one scalar are accepted as they are:
trk <- read.dti.trk("brain.trk");
write.dti.tsf(trk$tracks, "brain.trk.tsf");
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.