R6 class for compiling images to render in ggplot
R6 class for compiling images to render in ggplot
Details
Note that this class is exported only for power users and rarely needs to be called directly in typical use of the package. Instead, look at images().
Active bindings
zero_tol
the (positive) numeric value that should be treated as indistinguishable from zero. This value is used to set small values in the images to exactly zero for proper masking. Default 1e-6
slices
a character vector of cached slice specifications to be used in $get_slices()
contrasts
a character vector of cached contrast specifications to be used in $get_slices()
Methods
Method new()
create ggbrain_images object consisting of one or more NIfTI images
Usage
ggbrain_images$new(images = NULL, volumes = NULL, labels = NULL, filter = NULL)
Arguments
images
a character vector of file names containing NIfTI images to read
volumes
the volumes to be read from each element of
images
. By default, this is 1, in which case the first volume is used, which is appropriate for all 3-D images. For 4-D images,volumes
gives you more flexibility over the volume to display.labels
A named list of data.frames with labels that map to values in the integer-valued/atlas elements of
images
. If a single data.frame is passed, it will be accepted if only a single image is passed, too. These are then assumed to correspondfilter
A named list of filter expressions to be applied to particular images. The names of the list correspond to the names of the
images
provided. Each element of the list can either be a character vector denoting a filtering expression (e.g.,'value < 100'
) or a numeric vector denoting values of the image that should be retained (e.g.,c(5, 10, 12)
).
Method add_labels()
add a labels data.frame that connects an integer-valued image with a set of labels
Arguments
...
named arguments containing data.frame objects for each image to be labeled. The argument name should match the image name to be labeled and the value should be a data.frame containing
value
andlabel
.
Details
As a result of $add_labels, the $get_slices method will always remap the numeric values for label images to the corresponding text-based labels in the label data. In addition, a new attribute will be returned called "slice_labels" that contains a row for each region represented in each slice.
Method dim()
return the 3D dimensions of the images contained in this object
Method winsorize_images()
winsorize the tails of a set of images to pull in extreme values
Usage
ggbrain_images$winsorize_images(img_names, quantiles = c(0.001, 0.999))
Method get_nz_indices()
return the indices of non-zero voxels
Method add_slices()
adds one or more slices to the cached slices that will be retrieved by
$get_slices() when no slices
argument is passed.
Method add_contrasts()
adds one or more contrasts to the cached contrasts that will be retrieved by
$get_slices() when no contrasts
argument is passed.
Method get_slices()
get slice data for one or more slices based on their coordinates
Usage
ggbrain_images$get_slices(
slices = NULL,
img_names = NULL,
contrasts = NULL,
fill_labels = FALSE,
make_square = TRUE,
remove_null_space = TRUE
)
Arguments
slices
a vector of slice positions
img_names
a character vector of images contained in the ggbrain_images object to be sliced
contrasts
a named character vector of contrasts to be calculated for each slice
fill_labels
if TRUE, the numeric value of the image will be used for any value that does not have a corresponding label in the labels data.frame. Default: FALSE
make_square
If TRUE, make all images square and of the same size
remove_null_space
If TRUE, remove slices where all values are approximately zero
Details
This function always returns a data.frame where each row represents a slice requested by the user. The $slice_data element is a list-column where each element is itself a list of slice data for a given layer/image (e.g., underlay or overlay) . The $slice_matrix is a list-column where each element is a list of 2-D matrices, one per layer/image. @return a ggbrain_slices object containing the requested slices and contrasts
Method get_slices_inplane()
get_slices_inplane is mostly an internal funciton for getting one or more slices from a given plane
Method lookup_slices()
internal function to lookup which slices to display along each axis based on their quantile, xyz coordinate, or ijk coordinate