patches_to_volume: Convert Patches to a Volume

Description Usage Arguments Value Examples

View source: R/patches_to_volume.R

Description

Convert Patches to a Volume

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
patches_to_volume(patches, indices, patchsize, verbose = TRUE, orig_dim = NULL)

get_volume_from_patches(
  patches,
  indices,
  patchsize,
  verbose = TRUE,
  invert_pad = TRUE,
  orig_dim = NULL
)

Arguments

patches

A matrix of patches, generally from volume_to_patches

indices

A matrix of 3 by num_patches indices for the data to extract

patchsize

Vector of length 2 (or more)

verbose

print diagnostic messages

orig_dim

Original dimensions of volume

invert_pad

Run invert_pad_image on the image before returning.

Value

A 3D volume

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
user = Sys.getenv("USER")
if (user %in% c("johnmuschelli", "travis") &
Sys.info()["sysname"] == "Darwin"){
reticulate::use_python(paste0(
"/Library/Frameworks/Python.framework/Versions/3.5/bin/python3"))
} else {
python = system("which python", intern = TRUE)
print(python)
reticulate::use_python(python)
}
library(neurobase)
fname = system.file("extdata", "MPRAGE.nii.gz", package = "flexconn")
t1 = readnii(fname)
fname = system.file("extdata", "FLAIR.nii.gz", package = "flexconn")
flair = readnii(fname)
patchsize = c(3, 3)
verbose = TRUE
patch = get_patches(t1, flair, mask = NULL, patchsize = patchsize,
only_patches = FALSE, normalize = FALSE)
out_mask = patch$mask
masked_t1 = mask_img(t1, out_mask)
t1_remade = get_volume_from_patches(patch$t1_patches,
indices = patch$indices,
patchsize = patchsize,
invert_pad = patch$pad)
stopifnot(all(dim(t1) == dim(t1_remade)))
t1vals = mask_vals(t1, out_mask)
t1_remade_vals = mask_vals(t1_remade, out_mask)
testthat::expect_equal(t1vals, t1_remade_vals)

neuroconductor/flexconn documentation built on Sept. 25, 2020, 10:51 a.m.