diff --git a/.Rbuildignore b/.Rbuildignore index d4e3ba1..9e21e23 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ +^\.Rhistory$ ^Doxyfile$ ^\.travis\.yml$ ^.*\.Rproj$ diff --git a/.Rhistory b/.Rhistory deleted file mode 100644 index 807a535..0000000 --- a/.Rhistory +++ /dev/null @@ -1,512 +0,0 @@ -rm(list=ls()) -nifti = c("sizeof_hdr", "data_type", "db_name", "extents", -"session_error", "regular", "dim_info", "dim_", -"intent_p1", "intent_p2", "intent_p3", "intent_code", -"datatype", "bitpix", "slice_start", "pixdim", -"vox_offset", "scl_slope", "scl_inter", "slice_end", -"slice_code", "xyzt_units", "cal_max", "cal_min", -"slice_duration", "toffset", "glmax", "glmin", -"descrip", "aux_file", "qform_code", "sform_code", -"quatern_b", "quatern_c", "quatern_d", "qoffset_x", -"qoffset_y", "qoffset_z", "srow_x", "srow_y", "srow_z", -"intent_name", "magic", "extender", ".Data") -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package="RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -hdr_names -hdr_off -img_off -setdiff(hdr_names, img_names) -hdr$dim -rm(list=ls()) -nifti = c("sizeof_hdr", "data_type", "db_name", "extents", -"session_error", "regular", "dim_info", "dim_", -"intent_p1", "intent_p2", "intent_p3", "intent_code", -"datatype", "bitpix", "slice_start", "pixdim", -"vox_offset", "scl_slope", "scl_inter", "slice_end", -"slice_code", "xyzt_units", "cal_max", "cal_min", -"slice_duration", "toffset", "glmax", "glmin", -"descrip", "aux_file", "qform_code", "sform_code", -"quatern_b", "quatern_c", "quatern_d", "qoffset_x", -"qoffset_y", "qoffset_z", "srow_x", "srow_y", "srow_z", -"intent_name", "magic", "extender", ".Data") -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package="RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -setdiff(hdr_names, img_names) -rm(list=ls()) -nifti = c("sizeof_hdr", "data_type", "db_name", "extents", -"session_error", "regular", "dim_info", "dim_", -"intent_p1", "intent_p2", "intent_p3", "intent_code", -"datatype", "bitpix", "slice_start", "pixdim", -"vox_offset", "scl_slope", "scl_inter", "slice_end", -"slice_code", "xyzt_units", "cal_max", "cal_min", -"slice_duration", "toffset", "glmax", "glmin", -"descrip", "aux_file", "qform_code", "sform_code", -"quatern_b", "quatern_c", "quatern_d", "qoffset_x", -"qoffset_y", "qoffset_z", "srow_x", "srow_y", "srow_z", -"intent_name", "magic", "extender", ".Data") -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package="RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -add -img@datatype -img@data_type -rm(list=ls()) -library(oro.nifti) -# options(error = quote(print("Error Ocurred"))) -URL <- "http://imaging.mrc-cbu.cam.ac.uk/downloads/Colin/colin_1mm.tgz" -urlfile <- file.path("~/Desktop/scratch/", "colin_1mm.tgz") -# if (!file.exists(urlfile)){ -download.file(URL, dest=urlfile, quiet=TRUE) -untar(urlfile, exdir=path.expand("~/Desktop/scratch/")) -# } -img <- readNIfTI(file.path("~/Desktop/scratch/", "colin_1mm"), verbose=TRUE) -# img_corr <- readNIfTI(file.path("~/Desktop/scratch/", "ncolin_1mm"), -# verbose=TRUE) -readNifti(file.path("~/Desktop/scratch/", "colin_1mm")) -image =readNifti(file.path("~/Desktop/scratch/", "colin_1mm")) -writeNifti(image, file = tempfile(fileext = ".nii.gz")) -?nifti -rm(list=ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -# rnii2oro = function(image) { -arr = as(image, "array") -hdr = dumpNifti(image) -dtype = hdr$datatype -hdr$reorient = FALSE -img = nifti(arr) -####################################### -# Get the names -####################################### -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -####################################### -# Stop if these have changed -####################################### -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -####################################### -# See where they both work -####################################### -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -add = setdiff(img_names, hdr_names) -add -img@session_error -rm(list=ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -# rnii2oro = function(image) { -arr = as(image, "array") -hdr = dumpNifti(image) -dtype = hdr$datatype -hdr$reoriented = FALSE -img = nifti(arr) -####################################### -# Get the names -####################################### -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -####################################### -# Stop if these have changed -####################################### -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -####################################### -# See where they both work -####################################### -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -####################################### -# -####################################### -add = setdiff(img_names, hdr_names) -# } -add -img@reoriented -img_off -rm(list=ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -# rnii2oro = function(image) { -arr = as(image, "array") -hdr = dumpNifti(image) -dtype = hdr$datatype -img = nifti(arr) -####################################### -# Get the names -####################################### -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -####################################### -# Stop if these have changed -####################################### -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -####################################### -# See where they both work -####################################### -both = intersect(img_names, hdr_names) -####################################### -# -####################################### -add = setdiff(img_names, hdr_names) -for (islot in both) { -slot(img, islot) = hdr[[islot]] -} -# } -rm(list=ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -img_off -source('~/Desktop/fastnii.R') -rm(list=ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -# rnii2oro = function(image) { -arr = as(image, "array") -hdr = dumpNifti(image) -dtype = hdr$datatype -img = nifti(arr) -####################################### -# Get the names -####################################### -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -####################################### -# Stop if these have changed -####################################### -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -wrong -source('~/Desktop/fastnii.R') -img -writenii(img, filename = tempfile(fileext = ".nii.gz")) -writeNIfTI(img, filename = tempfile(fileext = ".nii.gz")) -class(image) -library(RNifti) -rm(list = ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -img_off -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -img = oro.nifti::readNIfTI(fname) -out = nii2oro(image) -nii2oro -arr = as(image, "array") -hdr = dumpNifti(image) -hdr_names = sort(names(hdr)) -stopifnot( !("dim_" %in% names(hdr))) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = nifti(arr) -img -img_names = sort(slotNames(img)) -####################################### -# Stop if these have changed -# This means one of the standards have changed -####################################### -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -wrong -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -img = oro.nifti::readNIfTI(fname) -out = nii2oro(image) -out -all.equal(out, img) -out@regular -img@regular -rm(list = ls()) -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -hdr = dumpNifti(image) -hdr$dim_ = hdr$dim -hdr$dim = NULL -img = readNIfTI(fname, reorient = FALSE) -img_names = sort(slotNames(img)) -hdr_names = sort(names(hdr)) -wrong = setdiff(hdr_names, img_names) -stopifnot(length(wrong) == 0) -add = setdiff(img_names, hdr_names) -both = intersect(img_names, hdr_names) -hdr_vals = lapply(both, function(x){ -hdr[[x]] -}) -img_vals = lapply(both, function(x){ -slot(img, x) -}) -names(hdr_vals) = names(img_vals) = both -check = mapply(function(x, y){ -all(x == y) -}, hdr_vals, img_vals) -img_off = img_vals[!check] -hdr_off = hdr_vals[!check] -img_off -hdr_vals -img_vals -ig -img -out -img@regular -oro.nifti:::readNIfTI() -oro.nifti:::readNIfTI -oro.nifti::: .read.nifti.content -img@datatype -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -img = oro.nifti::readNIfTI(fname, reorient = FALSE) -out = nii2oro(image) -all.equal(out) -all.equal(out, img) -nifti -source('~/Desktop/fastnii.R') -hdr$qform_code -hdr$regular -img@regular -add = setdiff(img_names, hdr_names) -add -library(RNifti) -library(oro.nifti) -fname = system.file("extdata", "example.nii.gz", package = "RNifti") -image <- readNifti(fname) -img = oro.nifti::readNIfTI(fname, reorient = FALSE) -out = nii2oro(image) -all.equal(out, img) -``` -out@bitpix -image$bitpix -out@bitpix -out@datatype -img@datatype -img@bitpix -fname -fslhd(fname) -library(fslr) -fslhd(fname) -fname -fslhd(fname)[1:10] -fslhd(fname)[c(1, 4, 11:20)] -fslhd(fname)[c(1, 4, 15:17)] -library(RNifti) -?readNifti -file = system.file("extdata", "example.nii.gz") -is.niftiImage(file) -img = readNifti(file) -is.niftiImage(img) -is.internalImage(img) -int_img = readNifti(file, internal = TRUE) -is.niftiImage(int_img) -is.internalImage(int_img)