The function offers the possibility to write ".txt", ".dat", ".dat.gz", ".pet" or ".fif" files. Furthermore the graphic formats ".tif", ".tiff", ".pgm", ".ppm", ".png", ".pnm", ".gif", ".jpg" and ".jpeg" are supported. The function was especially written to handle sinograms and datasets, that are processed with the functions radon
, iradon
and iradonIT
of the R package 'PET'.
writeData(data, outputfile, fileHeader = NULL, imType = "normal",
fileOverwrite = "ASK", DebugLevel = "Normal")
(matrix) The data to be written out.
(character) outputfile
naming the file to write to, including the pathname. The path has to be given relatively to the working-directory of your R-session or it contains the full path of the file. The extension of the filename specifies the format. Currently, ".txt", ".dat", ".dat.gz", ".fif", ".pet" and the graphic formats ".tif", ".tiff", ".pgm", ".ppm", ".png", ".pnm", ".gif", ".jpg" and ".jpeg" are supported. See below to details to get more information about these formats.
(list) If the file format "is .dat", ".dat.gz", ".pet" or ".fif", then fileHeader
is necessary. If in these cases fileHeader=NULL
, default values will be generated dependent on imType
. See below to details to get more information.
(character) imType
specifies the type of data
and thus the default values of fileHeader
. Default is imType="normal"
. Additional implementation is imType="radon"
, i.e. that the image is a sinogram (Radon transformed image).
(character) Control the behaviour for overwriting a file. Supported are "NO", "YES" and "ASK". If fileOverwrite = "ASK" the routine will ask you in case of an existing outputfile with this name. Default is "ASK".
(character) This parameter controls the level of output. Defaults to DebugLevel="Normal"
for a standard level output. Alternative implementations are "Detail"
if it is desirable to show almost all output on screen or "HardCore"
for no information at all.
writeData
creates a file, but returns nothing.
In the following different supported formats of inputfile
are explained. For ".dat", ".dat.gz", ".pet" and ".fif" the default values dependent on imType
are defined.
".tif", ".tiff", ".pgm", ".ppm", ".png", ".pnm", ".gif", ".jpg" and ".jpeg"
For using these graphic formats the R package adimpro
is necessary. See there, to get more information about these formats.
".txt"
Writes files in ASCII format without header, which contain only the raw data. The R-routine write.table
is used.
".dat" and ".gz"
Write files in ASCII format where files contain a header with three or four rows followed by the data. Compared to ".txt" the advantage is that is possible to save and load higher-dimensional data. Furthermore important values are saved, that are needed for Radon and the inverse Radon transformation. If the extension ".gz" is specified, then files in ".dat" format will be stored which are additionally compressed by 'gzip'.
Assuming the data are two-dimensional, at first fileHeader
will be written out. Default values will be defined (dependent on imType
) for not specified parameters. The file has only the following form:
Description: char (optional)
SignalDim: int int
XYmin: double double
DeltaXY: double double
... and after the header data
will be written out
Explanation of the parameters:
Description: | Can be a short description of the data. It is possible |
to leave out this parameter. In this case the first | |
line of the file begins with 'SignalDim'. | |
SignalDim: | In case of 2-dim data, 'SignalDim' is the number of |
rows and columns of the array, but also a greater | |
dimension is permissible. | |
XYmin: | Leftmost coordinate and lowest coordinate of the |
data. | |
DeltaXY: | Quantization steps in image, in x and y-direction. |
Defaults to:
imType="normal" |
imType="radon" |
|
SignalDim: | dim(data) |
dim(data) |
XYmin: | -0.5*(dim(data)-1) |
c(0,-0.5*(ncol(data)-1)) |
DeltaXY: | c(1,1) |
c(pi/(nrow(data)),1) |
If the dimension of data is greater than two, the number of 'SignalDim', 'XYmin' and 'DeltaXY' should be increased appropriately. Note in this case you must define the fileHeader
.
".pet"
Writes a picture in ".pet" format (raw float with header) to the file e.g. inputfile = "FileName.pet"
(binary format). The ".pet"-file has to be of the following structure: The first part contains a header and the second part the data, e.g. an image.
Only the values of the parameters are saved in the header and not the parameter names.
Description: | (80-byte character) Should be a short description of |
image. Defaults to Description="}\eqn{\backslash 0}{\0}\code{" . |
|
XSamples: | (integer) Number of rows of array. Defaults |
to XSamples=nrow(data) . |
|
YSamples: | (integer) Number of columns of array. Defaults |
to YSamples=ncol(data) . |
|
Xmin: | (float) Leftmost coordinate in original image. |
If imType="normal" then defaults to Xmin= |
|
-0.5*(nrow(data)-1) or if imType="radon" |
|
then Xmin=0 . |
|
Ymin: | (float) Lowest coordinate in original image. |
Defaults to Ymin=-0.5*(ncol(data)-1) . |
|
DeltaX: | (float) Quantization steps in original image (x). |
If imType="normal" then defaults to DeltaX=1 |
|
or if imType="radon" then DeltaX=pi/(nrow(data)) . |
|
DeltaY: | (float) Quantization steps in original image (y). |
Defaults to DeltaY=1 . |
The dimension of the data should be not greater than two.
The ".pet" and the sequencing ".fif" format will be used in the iradonIT
method to store iteration-steps and to read a references image.
".fif"
Writes a picture in ".fif" format (raw float with header) to the file e.g. inputfile = "FileName.fif"
(binary format). The ".fif"-file has to be of the following structure: The first part contains a header and the second part the data, e.g. an image. At first the values of the following parameters are saved in the file:
FIFIdType: | (integer) ID used to restore FIF:17737:'\(\backslash 0\)''\(\backslash 0\)''E''I'. |
Defaults to FIFIdType=17737 . |
|
FileName: | (100-byte character) Name used for saving this image. |
Defaults to FileName=outputfile . |
|
Description: | See above. |
Date: | (10-byte character) Date (YYYY-MM-DD). Defaults to |
Date=as.character(Sys.Date()) . |
|
XSamples: | See above. |
YSamples: | See above. |
ArrayType: | (integer) Defines the format number: \(1\) for Real or |
\(2\) for Complex. Complex matrices are determined by \(A=a_{i,j}\) | |
where \(a_{i,2n}\) is the imaginary part to the real value | |
\(a_{i,2n-1}\), \(i=1,\ldots,M\), \(j=1,\ldots,2N\), \(n=1,\ldots,N\). | |
Defaults to ArrayType=1 . |
|
Xmin: | (float) See above. |
Ymin: | (float) See above. |
DeltaX: | (float) See above. |
DeltaY: | (float) See above. |
SignalMin: | (float) Lowest signalvalue in array. Defaults |
to SignalMax=max(data) . |
|
SignalMax: | (float) Highest signalvalue in array. Defaults |
to SignalMax=max(data) . |
After this header data
are following.
Schulz, Joern, Diploma Thesis: Analyse von PET Daten unter Einsatz adaptiver Glaettungsverfahren, Humboldt-Universitaet zu Berlin, Institut fuer Mathematik, 2006.
# NOT RUN {
P <- phantom(addIm="blurred1")
rP <- radon(P, RhoSamples=401)
irP <- iradon(rP$rData, 257, 257)
# Saving 'P' as a 'jpeg'-file
writeData(P, "Phantom.jpeg")
# Saving 'rP' as a 'pet'-file
writeData(rP$rData, "RadonPhantom.pet", fileHeader=rP$Header)
# Saving 'irP' as a 'dat.gz'-file'
writeData(irP$irData, "RecPhantom.dat.gz", fileHeader=irP$Header)
rm(irP,P,rP)
Image1 <- readData("Phantom.jpeg")
Image2 <- readData("RadonPhantom.pet")
Image3 <- readData("RecPhantom.dat.gz")
viewData(list(Image1,Image2$Signal,Image3$Signal))
rm(Image1,Image2,Image3)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab