Skip to content

Commit

Permalink
Fixing check_nifti.
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Apr 24, 2015
1 parent d695877 commit fb66b0a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
14 changes: 13 additions & 1 deletion R/check_nifti.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ setMethod("check_nifti", "nifti", function(x,

#' @rdname check_nifti-methods
#' @aliases check_nifti,character-method
#' @importFrom R.utils gunzip
#'
#' @export
setMethod("check_nifti", "character", function(x,
Expand Down Expand Up @@ -65,4 +64,17 @@ setMethod("check_nifti", "list", function(x,
})


#' @rdname check_nifti-methods
#' @aliases check_nifti,array-method
#' @export
setMethod("check_nifti", "array", function(x,
reorient=FALSE,
allow.array=FALSE) {
if (!allow.array){
stop("x is array but allow.array = FALSE")
}
return(x)
})



7 changes: 5 additions & 2 deletions R/dropEmptyImageDimensions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @param value Value to check against. If zero, then
#' \code{dropEmptyImageDimensions} will drop any dimension that has
#' all zeroes
#' @param threshold Drop dimension if fewer than \code{threshold} voxels
#' are in the slice
#' @param other.imgs List of other nifti objects or filenames
#' to apply the same dropping as \code{img}.
#' @param reorient Should image be reoriented if a filename?
Expand All @@ -13,6 +15,7 @@
#' @export
dropEmptyImageDimensions <- function(img,
value = 0,
threshold = 0,
other.imgs = NULL,
reorient = FALSE) {

Expand All @@ -28,8 +31,8 @@ dropEmptyImageDimensions <- function(img,
for (i in 1:3){
zero_x = apply(img, i, function(x) sum(x != value))
dzero_x = !(
cumsum(zero_x) == 0 |
rev( cumsum(rev(zero_x)) == 0 )
cumsum(zero_x) <= threshold |
rev( cumsum(rev(zero_x)) <= threshold )
)
inds[[i]] = which(dzero_x)
# print(i)
Expand Down
3 changes: 3 additions & 0 deletions man/check_nifti-methods.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
\docType{methods}
\name{check_nifti-methods}
\alias{check_nifti}
\alias{check_nifti,array-method}
\alias{check_nifti,character-method}
\alias{check_nifti,list-method}
\alias{check_nifti,nifti-method}
Expand All @@ -16,6 +17,8 @@ check_nifti(x, reorient = FALSE, allow.array = FALSE)
\S4method{check_nifti}{character}(x, reorient = FALSE, allow.array = FALSE)

\S4method{check_nifti}{list}(x, reorient = FALSE, allow.array = FALSE)

\S4method{check_nifti}{array}(x, reorient = FALSE, allow.array = FALSE)
}
\arguments{
\item{x}{character path of image or
Expand Down
5 changes: 4 additions & 1 deletion man/dropEmptyImageDimensions.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\alias{dropEmptyImageDimensions}
\title{Drop Empty Image Dimensions}
\usage{
dropEmptyImageDimensions(img, value = 0, other.imgs = NULL,
dropEmptyImageDimensions(img, value = 0, threshold = 0, other.imgs = NULL,
reorient = FALSE)
}
\arguments{
Expand All @@ -14,6 +14,9 @@ dropEmptyImageDimensions(img, value = 0, other.imgs = NULL,
\code{dropEmptyImageDimensions} will drop any dimension that has
all zeroes}

\item{threshold}{Drop dimension if fewer than \code{threshold} voxels
are in the slice}

\item{other.imgs}{List of other nifti objects or filenames
to apply the same dropping as \code{img}.}

Expand Down

0 comments on commit fb66b0a

Please sign in to comment.