Title: | White Matter Normalization for Magnetic Resonance Images |
---|---|
Description: | Shinohara (2014) <doi:10.1016/j.nicl.2014.08.008> introduced 'WhiteStripe', an intensity-based normalization of T1 and T2 images, where normal appearing white matter performs well, but requires segmentation. This method performs white matter mean and standard deviation estimates on data that has been rigidly-registered to the 'MNI' template and uses histogram-based methods. |
Authors: | R. Taki Shinohara [aut], John Muschelli [aut, cre] |
Maintainer: | John Muschelli <[email protected]> |
License: | GPL-3 |
Version: | 2.4.3 |
Built: | 2024-11-05 04:12:42 UTC |
Source: | https://github.com/muschellij2/whitestripe |
Download T1 and T2 data for Examples
download_img_data(lib.loc = NULL)
download_img_data(lib.loc = NULL)
lib.loc |
a character vector with path names of R libraries.
Passed to |
Logical indicator if the files were downloaded.
This function outputs the nth derivative of a histogram smooth.
get.deriv.smooth.hist(x, coefs, knots, deg = 4, deriv.deg = 1)
get.deriv.smooth.hist(x, coefs, knots, deg = 4, deriv.deg = 1)
x |
values from smooth_hist |
coefs |
Coefficients from GAM from smooth_hist |
knots |
Number of knots fit for GAM |
deg |
Degree of polynomials |
deriv.deg |
The degree of the derivative. |
Derivative of smoothed histogram
data(smoothed_histogram) dy<-get.deriv.smooth.hist(xvals, coefs=s.hist$coefs, knots=s.hist$knots, deg=s.hist$deg, deriv.deg=1)
data(smoothed_histogram) dy<-get.deriv.smooth.hist(xvals, coefs=s.hist$coefs, knots=s.hist$knots, deg=s.hist$deg, deriv.deg=1)
This function grabs the first peak or shoulder.
get.first.mode(x, y, rare.prop = 1/5, verbose = TRUE, remove.tail = TRUE, ...)
get.first.mode(x, y, rare.prop = 1/5, verbose = TRUE, remove.tail = TRUE, ...)
x |
values of midpoints from |
y |
values of counts from |
rare.prop |
Proportion used to remove rare intensity tail |
verbose |
print diagnostic output |
remove.tail |
Remove rare intensity tail |
... |
arguments to be passed to |
Value of x that is the first peak
data(t1.voi.hist) system.time({ y = t1.voi.hist$counts x = t1.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 20 used for speed of example nawm_peak = get.first.mode(x, y, k=20) plot(t1.voi.hist, border="red") abline(v=nawm_peak) })
data(t1.voi.hist) system.time({ y = t1.voi.hist$counts x = t1.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 20 used for speed of example nawm_peak = get.first.mode(x, y, k=20) plot(t1.voi.hist, border="red") abline(v=nawm_peak) })
This function grabs the largest peak of the histogram
get.largest.mode(x, y, verbose = TRUE, ...)
get.largest.mode(x, y, verbose = TRUE, ...)
x |
values of midpoints from |
y |
values of counts from |
verbose |
print diagnostic output |
... |
arguments to be passed to |
Value of x that is the largest peak
data(t2.voi.hist) system.time({ y = t2.voi.hist$counts x = t2.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 30 used for speed of example nawm_peak = get.largest.mode(x, y, k=30) plot(t2.voi.hist, border="red") abline(v=nawm_peak) })
data(t2.voi.hist) system.time({ y = t2.voi.hist$counts x = t2.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 30 used for speed of example nawm_peak = get.largest.mode(x, y, k=30) plot(t2.voi.hist, border="red") abline(v=nawm_peak) })
This function grabs the last peak or shoulder.
get.last.mode(x, y, rare.prop = 1/5, verbose = TRUE, remove.tail = TRUE, ...)
get.last.mode(x, y, rare.prop = 1/5, verbose = TRUE, remove.tail = TRUE, ...)
x |
values of midpoints from |
y |
values of counts from |
rare.prop |
Proportion used to remove rare intensity tail |
verbose |
print diagnostic output |
remove.tail |
Remove rare intensity tail |
... |
arguments to be passed to |
Value of x that is the last peak
data(t1.voi.hist) system.time({ y = t1.voi.hist$counts x = t1.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 20 used for speed of example nawm_peak = get.last.mode(x, y, k=20) plot(t1.voi.hist, border="red") abline(v=nawm_peak) })
data(t1.voi.hist) system.time({ y = t1.voi.hist$counts x = t1.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 20 used for speed of example nawm_peak = get.last.mode(x, y, k=20) plot(t1.voi.hist, border="red") abline(v=nawm_peak) })
Creates a VOI of Image for the specified slices
make_img_voi(img, slices = 80:120, na.rm = TRUE, ...)
make_img_voi(img, slices = 80:120, na.rm = TRUE, ...)
img |
Image (T1 usually or T2). Array or object of class nifti |
slices |
Slices to take for the image voi |
na.rm |
Remove NAs from mean. This is for double checking |
... |
Arguments passed from other methods (not used) |
VOI of image.
Smoothed histogram of image
s.hist
s.hist
A GAM from mgcv
for x and y from histograms
## Not run: data(t2.voi.hist) y = t2.voi.hist$counts x = t2.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 70 used for speed of example s.hist = smooth_hist(x, y, k=70) ## End(Not run)
## Not run: data(t2.voi.hist) y = t2.voi.hist$counts x = t2.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 70 used for speed of example s.hist = smooth_hist(x, y, k=70) ## End(Not run)
Uses a generalized additive model (GAM) to smooth a histogram for whitestripe
smooth_hist( x, y, deg = 4, k = floor(min(250, length(x)/2)), method = "REML", ... )
smooth_hist( x, y, deg = 4, k = floor(min(250, length(x)/2)), method = "REML", ... )
x |
values of midpoints from |
y |
values of counts from |
deg |
degree of polynomials used |
k |
Number of knots |
method |
Method for smoothing for GAM |
... |
Arguments passed to |
List of objects: x and y coordinates of histogram, coefficients from GAM, fitted values from GAM, the GAM model, the knots fitted, and degrees of polynomials
data(t2.voi.hist) y = t2.voi.hist$counts x = t2.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 30 used for speed of example s.hist = smooth_hist(x, y, k=30) plot(t2.voi.hist, border="red") lines(s.hist)
data(t2.voi.hist) y = t2.voi.hist$counts x = t2.voi.hist$mids x = x[!is.na(y)]; y = y[!is.na(y)] # 30 used for speed of example s.hist = smooth_hist(x, y, k=30) plot(t2.voi.hist, border="red") lines(s.hist)
Histogram of VOI of T1 template image
t1.voi.hist
t1.voi.hist
A volume of interest histogram from a T1 image for smoothing
lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t1 = oro.nifti::readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t1.voi = make_img_voi(t1) any(is.na(t1.voi)) # FALSE t1.voi.hist = hist(t1.voi, breaks=2000, plot=FALSE) }
lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t1 = oro.nifti::readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t1.voi = make_img_voi(t1) any(is.na(t1.voi)) # FALSE t1.voi.hist = hist(t1.voi, breaks=2000, plot=FALSE) }
Histogram of VOI of T2 template image
t2.voi.hist
t2.voi.hist
A histogram volume of interest from a T2 image for smoothing
## Not run: lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t2 = readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2.voi = make_img_voi(t2) any(is.na(t2.voi)) # FALSE t2.voi.hist = hist(t2.voi, breaks=2000, plot=FALSE) #save(t2.voi.hist, file="data/t2.voi.hist.rda", compress = TRUE, # compression_level=9) } ## End(Not run)
## Not run: lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t2 = readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2.voi = make_img_voi(t2) any(is.na(t2.voi)) # FALSE t2.voi.hist = hist(t2.voi, breaks=2000, plot=FALSE) #save(t2.voi.hist, file="data/t2.voi.hist.rda", compress = TRUE, # compression_level=9) } ## End(Not run)
Returns the mean/sd of the whitestripe and indices for them on the image
whitestripe( img, type = c("T1", "T2", "FA", "MD", "first", "last", "largest"), breaks = 2000, whitestripe.width = 0.05, whitestripe.width.l = whitestripe.width, whitestripe.width.u = whitestripe.width, arr.ind = FALSE, verbose = TRUE, stripped = FALSE, slices = NULL, ... )
whitestripe( img, type = c("T1", "T2", "FA", "MD", "first", "last", "largest"), breaks = 2000, whitestripe.width = 0.05, whitestripe.width.l = whitestripe.width, whitestripe.width.u = whitestripe.width, arr.ind = FALSE, verbose = TRUE, stripped = FALSE, slices = NULL, ... )
img |
Image (T1, T2, FA, or MD). Array or object of class nifti |
type |
T1, T2, FA, or MD image whitestripe |
breaks |
Number of breaks passed to |
whitestripe.width |
Radius of the white stripe |
whitestripe.width.l |
Lower Radius of the white stripe |
whitestripe.width.u |
Upper Radius of the white stripe |
arr.ind |
Whether indices should be array notation or not,
passed to |
verbose |
Print diagnostic information |
stripped |
Applying to skull-stripped image. NOTE: This does NOT do a
subset of slices, as |
slices |
slices to use for |
... |
Arguments to be passed to |
This function takes in an image and computes a window of the
distribution called the white stripe. If you wish to pass in values you have
subset, such as single from a skull-stripped image, you can pass in img
and set the class to img_voi
(class(img) = "img_voi"
) and this
will not rerun make_img_voi
.
List of indices of whitestripe, last mode of histogram, array/nifti of 0/1 corresponding to the mask, mean of whitestripe, standard deviation of whitestripe
## Not run: library(WhiteStripe) lib.loc = tempdir() if (WhiteStripe::download_img_data(lib.loc = lib.loc)){ library(oro.nifti) set.seed(1) t1 = readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t1.ind = whitestripe(t1, "T1") set.seed(2) t1_2 = readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t1_2.ind = whitestripe(t1_2, "T1") t1.mask = whitestripe_ind_to_mask(t1, t1.ind$whitestripe.ind) t1.mask[t1.mask == 0] = NA orthographic(t1, t1.mask, col.y="red") t2 = readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2.ind = whitestripe(t2, "T2") t2.mask = whitestripe_ind_to_mask(t2, t2.ind$whitestripe.ind) t2.mask[t2.mask == 0] = NA orthographic(t2, t2.mask, col.y="red") } ## End(Not run)
## Not run: library(WhiteStripe) lib.loc = tempdir() if (WhiteStripe::download_img_data(lib.loc = lib.loc)){ library(oro.nifti) set.seed(1) t1 = readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t1.ind = whitestripe(t1, "T1") set.seed(2) t1_2 = readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t1_2.ind = whitestripe(t1_2, "T1") t1.mask = whitestripe_ind_to_mask(t1, t1.ind$whitestripe.ind) t1.mask[t1.mask == 0] = NA orthographic(t1, t1.mask, col.y="red") t2 = readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2.ind = whitestripe(t2, "T2") t2.mask = whitestripe_ind_to_mask(t2, t2.ind$whitestripe.ind) t2.mask[t2.mask == 0] = NA orthographic(t2, t2.mask, col.y="red") } ## End(Not run)
Uses t1 and t2 WhiteStripe to get an intersection of the two masks for a hybrid approach
whitestripe_hybrid(t1, t2, ...)
whitestripe_hybrid(t1, t2, ...)
t1 |
T1 image, array or class nifti |
t2 |
T2 image, array or class nifti |
... |
arguments passed to |
List of indices of overlap mask, and overlap of class array or nifti
whitestripe
## Not run: lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t1 = readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2 = readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) ind = whitestripe_hybrid(t1, t2) } ## End(Not run)
## Not run: lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t1 = readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2 = readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) ind = whitestripe_hybrid(t1, t2) } ## End(Not run)
Uses WhiteStripe indices to create image mask
whitestripe_ind_to_mask(img, indices, writeimg = FALSE, ...)
whitestripe_ind_to_mask(img, indices, writeimg = FALSE, ...)
img |
Array or class nifti that is corresponds to dimensions of the images the indices were generated from |
indices |
indices from |
writeimg |
logical to write image or not |
... |
arguments to passed to |
Class of array or nifti depending on img
input
whitestripe, whitestripe_hybrid
lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t1 = oro.nifti::readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2 = oro.nifti::readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) ind = whitestripe_hybrid(t1, t2) mask = whitestripe_ind_to_mask(t1, ind$whitestripe.ind) oro.nifti::orthographic(mask) }
lib.loc = tempdir() if (download_img_data(lib.loc = lib.loc)){ t1 = oro.nifti::readNIfTI(system.file("T1Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) t2 = oro.nifti::readNIfTI(system.file("T2Strip.nii.gz", package="WhiteStripe", lib.loc = lib.loc)) ind = whitestripe_hybrid(t1, t2) mask = whitestripe_ind_to_mask(t1, ind$whitestripe.ind) oro.nifti::orthographic(mask) }
Taking the indices from white stripe to normalize the intensity values of the brain
whitestripe_norm(img, indices, ...)
whitestripe_norm(img, indices, ...)
img |
Array or object of class nifti |
indices |
Indices of white stripe from |
... |
Object of same class as img
, but normalized
Return filenames T1 and T2 data for example and vignettes
ws_img_data(lib.loc = NULL, warn = TRUE)
ws_img_data(lib.loc = NULL, warn = TRUE)
lib.loc |
a character vector with path names of R libraries.
Passed to |
warn |
Should a warning be printed if the images were not there |
Vector of filenames
Midpoints from VOI histogram
xvals
xvals
x values from histogram for VOI