Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e4bdb7
Showing
62 changed files
with
25,549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Package: RNifti | ||
Version: 0.1.0 | ||
Date: 2016-09-01 | ||
Title: Fast R and C++ Access to NIfTI Images | ||
Author: Jon Clayden | ||
Maintainer: Jon Clayden <code@clayden.org> | ||
Imports: Rcpp (>= 0.11.0) | ||
Suggests: testthat (>= 0.11.0) | ||
Enhances: oro.nifti, tractor.base | ||
LinkingTo: Rcpp | ||
Description: Provides very fast access to images stored in the NIfTI-1 file | ||
format <http://nifti.nimh.nih.gov/nifti-1>, with seamless synchronisation | ||
between compiled C and interpreted R code. Not to be confused with RNiftyReg, | ||
which provides tools for image registration. | ||
License: GPL-2 | ||
URL: https://github.com/jonclayden/RNifti | ||
BugReports: https://github.com/jonclayden/RNifti/issues | ||
Encoding: UTF-8 | ||
RoxygenNote: 5.0.1 | ||
NeedsCompilation: yes | ||
Packaged: 2016-09-01 11:49:57 UTC; jon | ||
Repository: CRAN | ||
Date/Publication: 2016-09-01 17:29:22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
fb6b2eadbba2d5e0ea958d3e0a8e45f1 *DESCRIPTION | ||
e20469301709fc7383310d95f9e8ab4e *NAMESPACE | ||
2490b4d109b227186f557977ad659dfa *R/image.R | ||
dc7142a5856b0b84ffc44662cf871530 *R/nifti.R | ||
0081869ffb660272f2ca812018d60958 *R/xform.R | ||
33e5b97691485f83c60e3d5c3f3a2cdc *R/zzz.R | ||
eb8256cd53aa01205304e37eb6dc8a53 *README.md | ||
ccc527aa65600337ed5e3f832c0eb443 *cleanup | ||
e1101581081b97d9032639597016d3d8 *cleanup.win | ||
30c091d208079613a19efc08f87849de *inst/extdata/example.nii.gz | ||
55418f98f35198af3318c4282618872c *inst/include/RNifti.h | ||
00aaa92498f68e61f506224a15ed8a4d *inst/include/RNiftiAPI.h | ||
e407ffd378be4080bee8c1f8076cd051 *inst/include/lib/NiftiImage.h | ||
fa8b37f676aab680816c08451fe7b1bd *inst/include/lib/print.h | ||
a34af6ec4b25ecc1a68459bbb5dc76c9 *inst/include/niftilib/nifti1.h | ||
f7137f566bbb76b092b1274e4ab599fe *inst/include/niftilib/nifti1_io.h | ||
5407d4c937d8f925665f71aad35c12fa *inst/include/zlib/zconf.h | ||
1c128a3b0a0fd84c1224754170ee7756 *inst/include/zlib/zlib.h | ||
6f799f7df2f427678edd3abcc5897ad6 *inst/include/znzlib/znzlib.h | ||
2cfd1772edd6b9dd9274a8bda954bb14 *man/dumpNifti.Rd | ||
2fd178c7fd10f45ef39114cd2000ddef *man/internalImage.Rd | ||
309e4f9d81ae01b7ec5804b16c3da953 *man/ndim.Rd | ||
a9eb96edafa817a296cf79e755cec722 *man/pixdim.Rd | ||
2d86c37391f594e57b951da0d28a841f *man/readNifti.Rd | ||
5cb66c2de80021acfeb35bce9767ff8b *man/retrieveNifti.Rd | ||
1f4522b43df68a13b6699029d31ce8d1 *man/updateNifti.Rd | ||
9825b9a8b44206110f5ae2a1ebcf8ad3 *man/voxelToWorld.Rd | ||
d919580d8145b971a7c9ee71b3c5ca86 *man/writeNifti.Rd | ||
bf143f6ef896f3bff808ba60804ea88a *man/xform.Rd | ||
4339fefce4c27fe7c58ef189cb849ac7 *src/Makevars | ||
a6f806acc64eb9b6b2b53b543f1f8b25 *src/init.cpp | ||
fd7273caae3c89c02d9c84ddeeb9ade0 *src/main.cpp | ||
0914eaaf0fca8668ad668d855c23036c *src/niftilib/nifti1_io.c | ||
ae3bbb54820e1d49fb90cbba222e973f *src/zlib/adler32.c | ||
7a734598f9792fee943b70b6da8d932f *src/zlib/compress.c | ||
1339c92938d2594a6eecfa21c374d1b6 *src/zlib/crc32.c | ||
f28d16b67efecdfafa0d816a7d982124 *src/zlib/crc32.h | ||
cd7826278ce9d9d9ed5abdefef50c3e2 *src/zlib/deflate.c | ||
7ceae74a13201f14c91623116af169c3 *src/zlib/deflate.h | ||
29d02cff161bde3e4e717b25a2ab7050 *src/zlib/gzclose.c | ||
715df37bf53af0dee6d018d0f34836ad *src/zlib/gzguts.h | ||
cb70e50d56c980fb8fd2e2e97bb9cd86 *src/zlib/gzlib.c | ||
62164548c5f9c89dc5e7d8ea382ffd8e *src/zlib/gzread.c | ||
cb95538e53e594b0d8a4bf4ecb2b5659 *src/zlib/gzwrite.c | ||
bdb9cc0c602c951ed5f0557798e15299 *src/zlib/infback.c | ||
9c14c1d95cee9f62465dedea7524c5fb *src/zlib/inffast.c | ||
f3669099d3f571dbc0426401ed5f50e3 *src/zlib/inffast.h | ||
7fa3e91804601b6618c915b76a8dc332 *src/zlib/inffixed.h | ||
46cb3a81ac3fa57789eba65cfecf754d *src/zlib/inflate.c | ||
8f1b05cdf36a269882a955071b140162 *src/zlib/inflate.h | ||
3d0a4fce4b156f064e9be2aef36a7897 *src/zlib/inftrees.c | ||
ec87be89b9bcca8ced80a70f857e823b *src/zlib/inftrees.h | ||
bc195d555c24fecff56af6c06bd55b1d *src/zlib/trees.c | ||
51fdcb3e2ccf60ca13c06920c89296a3 *src/zlib/trees.h | ||
eabe905cdd27f5b935e6378cd0253418 *src/zlib/uncompr.c | ||
fff257bc1656eb60fc585a7dc35f963d *src/zlib/zutil.c | ||
de91a463004fd5b944c3d37eab0c1794 *src/zlib/zutil.h | ||
db1082070d31f780ebd9c051b74adc17 *src/znzlib/znzlib.c | ||
d4a2abbb6217055b8900c8d86ac6aa53 *tests/testthat.R | ||
4b0fe74a7776bec4fa562d998fb06226 *tests/testthat/test-05-nifti.R | ||
67e97715d9000e8325d9f2e38351db0b *tests/testthat/test-10-xform.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method("dim<-",internalImage) | ||
S3method("pixdim<-",default) | ||
S3method("pixunits<-",default) | ||
S3method(as.array,internalImage) | ||
S3method(dim,internalImage) | ||
S3method(pixdim,default) | ||
S3method(pixunits,default) | ||
S3method(print,niftiHeader) | ||
S3method(print,niftiImage) | ||
export("pixdim<-") | ||
export("pixunits<-") | ||
export("qform<-") | ||
export("sform<-") | ||
export(dumpNifti) | ||
export(ndim) | ||
export(pixdim) | ||
export(pixunits) | ||
export(readNifti) | ||
export(retrieveNifti) | ||
export(updateNifti) | ||
export(voxelToWorld) | ||
export(worldToVoxel) | ||
export(writeNifti) | ||
export(xform) | ||
importFrom(Rcpp,evalCpp) | ||
importFrom(utils,object.size) | ||
useDynLib(RNifti) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
#' Internal images | ||
#' | ||
#' An internal image is a simple R object with a few attributes including a | ||
#' pointer to an internal C structure, which contains the full image data. They | ||
#' are used in the package for efficiency, but can be converted to a normal | ||
#' R array using the \code{as.array} method. Attributes of these objects should | ||
#' not be changed. | ||
#' | ||
#' @param x An \code{"internalImage"} object. | ||
#' @param value Not used. Changing the dimensions of an internal image is | ||
#' invalid, and will produce an error. | ||
#' @param ... Additional parameters to methods. Currently unused. | ||
#' | ||
#' @author Jon Clayden <code@@clayden.org> | ||
#' @aliases internalImage | ||
#' @rdname internalImage | ||
#' @export | ||
dim.internalImage <- function (x) | ||
{ | ||
return (attr(x, "imagedim")) | ||
} | ||
|
||
#' @rdname internalImage | ||
#' @export | ||
"dim<-.internalImage" <- function (x, value) | ||
{ | ||
stop("Dimensions of an internal image cannot be changed") | ||
} | ||
|
||
#' @rdname internalImage | ||
#' @export | ||
as.array.internalImage <- function (x, ...) | ||
{ | ||
return (.Call("pointerToArray", x, PACKAGE="RNifti")) | ||
} | ||
|
||
#' @export | ||
print.niftiImage <- function (x, ...) | ||
{ | ||
dim <- dim(x) | ||
ndim <- length(dim) | ||
pixdim <- attr(x, "pixdim") | ||
pixunits <- attr(x, "pixunits") | ||
|
||
if ("internalImage" %in% class(x)) | ||
cat(paste0("Internal image: \"", x, "\"\n")) | ||
else | ||
cat(paste0("Image array of mode \"", storage.mode(x), "\" (", format(object.size(x),"auto"), ")\n")) | ||
|
||
cat(paste("-", paste(dim,collapse=" x "), ifelse(ndim>2,"voxels\n","pixels\n"))) | ||
|
||
if (!is.null(pixdim)) | ||
{ | ||
spaceUnit <- grep("m$", pixunits, perl=TRUE, value=TRUE) | ||
cat(paste("-", paste(signif(pixdim[1:min(3,ndim)],4),collapse=" x "))) | ||
if (length(spaceUnit) > 0) | ||
cat(paste0(" ", spaceUnit[1])) | ||
|
||
if (ndim > 3) | ||
{ | ||
timeUnit <- grep("s$", pixunits, perl=TRUE, value=TRUE) | ||
cat(paste(" x", signif(pixdim[4],4))) | ||
if (length(timeUnit) > 0) | ||
cat(paste0(" ", timeUnit[1])) | ||
} | ||
if (ndim > 4) | ||
cat(paste(" x", paste(signif(pixdim[5:ndim],4),collapse=" x "))) | ||
|
||
cat(paste(" per", ifelse(ndim>2,"voxel\n","pixel\n"))) | ||
} | ||
} | ||
|
||
#' Number of dimensions | ||
#' | ||
#' This function is shorthand for \code{length(dim(object))}. | ||
#' | ||
#' @param object An R object. | ||
#' @return The dimensionality of the object. Objects without a \code{dim} | ||
#' attribute will produce zero. | ||
#' | ||
#' @author Jon Clayden <code@@clayden.org> | ||
#' @export | ||
ndim <- function (object) | ||
{ | ||
length(dim(object)) | ||
} | ||
|
||
#' Pixel dimensions and units | ||
#' | ||
#' By default, these generic functions return or replace the \code{"pixdim"} | ||
#' and \code{"pixunits"} attributes of their arguments. These represent the | ||
#' physical step size between pixel or voxel centre points, and the spatial and | ||
#' temporal units that they are given in. The former defaults to 1 in each | ||
#' dimension, if there is no attribute. | ||
#' | ||
#' @param object An R object, generally an image. | ||
#' @param value Numeric vector of pixel dimensions along each axis, or | ||
#' character vector of abbreviated units. For dimensions, a scalar | ||
#' \code{value} will be recycled if necessary. | ||
#' @return \code{pixdim} returns a numeric vector of pixel dimensions. | ||
#' \code{pixunits} returns a character vector of length up to two, giving the | ||
#' spatial and temporal unit names. | ||
#' | ||
#' @author Jon Clayden <code@@clayden.org> | ||
#' @export | ||
pixdim <- function (object) | ||
{ | ||
UseMethod("pixdim") | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
pixdim.default <- function (object) | ||
{ | ||
if (!is.null(attr(object, "pixdim"))) | ||
return (attr(object, "pixdim")) | ||
else if (!is.null(dim(object))) | ||
return (rep(1, length(dim(object)))) | ||
else | ||
return (1) | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
"pixdim<-" <- function (object, value) | ||
{ | ||
UseMethod("pixdim<-") | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
"pixdim<-.default" <- function (object, value) | ||
{ | ||
if ("internalImage" %in% class(object)) | ||
stop("Pixel dimensions of an internal image cannot be changed") | ||
|
||
if (is.numeric(value)) | ||
{ | ||
if (length(value) == ndim(object)) | ||
attr(object, "pixdim") <- value | ||
else if (length(value) == 1) | ||
attr(object, "pixdim") <- rep(value, ndim(object)) | ||
} | ||
return (object) | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
pixunits <- function (object) | ||
{ | ||
UseMethod("pixunits") | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
pixunits.default <- function (object) | ||
{ | ||
if (!is.null(attr(object, "pixunits"))) | ||
return (attr(object, "pixunits")) | ||
else | ||
return ("Unknown") | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
"pixunits<-" <- function (object, value) | ||
{ | ||
UseMethod("pixunits<-") | ||
} | ||
|
||
#' @rdname pixdim | ||
#' @export | ||
"pixunits<-.default" <- function (object, value) | ||
{ | ||
if ("internalImage" %in% class(object)) | ||
stop("Pixel units of an internal image cannot be changed") | ||
|
||
if (is.character(value)) | ||
attr(object, "pixunits") <- value | ||
|
||
return (object) | ||
} |
Oops, something went wrong.