```{r t1viz1a, warning=FALSE, message=FALSE, echo = FALSE}
csf_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 1)
}, t1s, tissues, SIMPLIFY = FALSE)
csf_dens = lapply(csf_vals, density)
plot_densities(csf_dens, main = "CSF Before")
```
```{r wbViz1, warning=FALSE, message=FALSE, echo = FALSE}
csf_norm_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 1)
}, t1_norm, tissues, SIMPLIFY = FALSE)
csf_norm_dens = lapply(csf_norm_vals, density)
plot_densities(csf_norm_dens,
xlab = "Whole-brain Normalized Intensities",
main = "CSF After")
```

## Whole-brain normalized intensities
- Gray matter distributions are more comparable.
```{r t1viz2a, warning=FALSE, message=FALSE, echo = FALSE}
gm_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 2)
}, t1s, tissues, SIMPLIFY = FALSE)
gm_dens = lapply(gm_vals, density)
plot_densities(gm_dens, main = "Gray Matter Before")
```
```{r wbViz2, warning=FALSE, message=FALSE, echo = FALSE}
gm_norm_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 2)
}, t1_norm, tissues, SIMPLIFY = FALSE)
gm_norm_dens = lapply(gm_norm_vals, density)
plot_densities(gm_norm_dens,
xlab = "Whole-brain Normalized Intensities",
main = "Gray Matter After")
```

## Whole-brain normalized intensities
- White matter distributions are more comparable.
```{r t1viz3a, warning=FALSE, message=FALSE, echo = FALSE}
wm_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 3)
}, t1s, tissues, SIMPLIFY = FALSE)
wm_dens = lapply(wm_vals, density)
plot_densities(wm_dens, main = "White Matter Before")
```
```{r wbViz3, warning=FALSE, message=FALSE, echo = FALSE}
wm_norm_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 3)
}, t1_norm, tissues, SIMPLIFY = FALSE)
wm_norm_dens = lapply(wm_norm_vals, density)
plot_densities(wm_norm_dens,
xlab = "Whole-brain Normalized Intensities",
main = "White Matter After")
```

## Other Normalizations: White Stripe
- Whole-brain normalization may be sensitive to outliers.
- Lesions in MS can have very high intensities, which lead to bad estimates of mean/variance
- Other more robust transformations may be used, such as using the median to center, IQR to scale, etc.
- White Stripe [@shinohara2014statistical] is based on parameters obtained from a sample of normal appearing white matter (NAWM), which is robust to outliers.
- The idea is to make normal appearing white matter comparable across subjects and visits.
## White Stripe normalization
Procedure:
1. Find white matter area on histogram
## White Stripe normalization
Procedure:
1. Find white matter area on histogram
2. Estimate mean $\mu_{WS}$ and variance $\sigma_{WS}$ of voxel intensities in that area
3. Normalize with those means/variances:
$$ T1_{WS} = \frac{T1 - \mu_{WS}}{\sigma_{WS}}$$
## White Stripe normalization
- After normalization, NAWM will have a standard normal distribution and units will be in standard deviations of NAWM.
- Gray matter and CSF distributions may not be comparable after White Stripe.
## White Stripe normalization
Procedure:
1. Find white matter area on histogram
2. Estimate mean $\mu_{WS}$ and variance $\sigma_{WS}$ of voxel intensities in that area
3. Normalize with those means/variances:
$$ T1_{WS} = \frac{T1 - \mu_{WS}}{\sigma_{WS}}$$
- After normalization, NAWM will have a standard normal distribution and units will be in standard deviations of NAWM.
- Gray matter and CSF distributions may not be comparable after White Stripe.
## White Stripe normalization code
```{r ws_show, eval=FALSE, warning = FALSE, message = FALSE, results='hide'}
library(WhiteStripe)
ind = whitestripe(img = t1, type = "T1", stripped = TRUE)$whitestripe.ind
ws_t1 = whitestripe_norm(t1, indices = ind)
```
- The `whitestripe` function takes an image, image type (in our case T1), and a logical indicating whether the image has been skull stripped.
- The indicies of voxels in the NAWM used for estimating the normalization parameters are located in the list element `$whitestripe.ind`.
- The function `whitestripe_norm` takes an image and the indicies from a call to `whitestripe` and returns the White Stripe normalized image as a nifti.
```{r ws, echo=FALSE, warning = FALSE, message = FALSE, results='hide'}
ws_norm = function(t1) {
ind = whitestripe(img = t1,
type = "T1",
stripped = TRUE)$whitestripe.ind
whitestripe_norm(t1, indices = ind)
}
t1_ws_norm = lapply(t1s, ws_norm)
```
## WhiteStripe normalized intensities
```{r wbViz1a, warning=FALSE, message=FALSE, echo = FALSE}
plot_densities(csf_norm_dens,
xlab = "Whole-brain Normalized Intensities", main = "Whole-brain: CSF")
```
```{r ws_viz_csf, warning=FALSE, message=FALSE, echo = FALSE}
csf_ws_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 1)
}, t1_ws_norm, tissues, SIMPLIFY = FALSE)
csf_ws_dens = lapply(csf_ws_vals, density)
plot_densities(csf_ws_dens,
xlab = "WhiteStripe Normalized Intensities", main = "White Stripe: CSF")
```

## WhiteStripe normalized intensities
```{r wbViz2a, warning=FALSE, message=FALSE, echo = FALSE}
plot_densities(gm_norm_dens,
xlab = "Whole-brain Normalized Intensities", main = "Whole-brain: Gray Matter")
```
```{r ws_viz_gm, warning=FALSE, message=FALSE, echo = FALSE}
gm_ws_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 2)
}, t1_ws_norm, tissues, SIMPLIFY = FALSE)
gm_ws_dens = lapply(gm_ws_vals, density)
plot_densities(gm_ws_dens,
xlab = "WhiteStripe Normalized Intensities", main = "White Stripe: Gray Matter")
```

## WhiteStripe normalized intensities
```{r wbViz3a, warning=FALSE, message=FALSE, echo = FALSE}
plot_densities(wm_norm_dens,
xlab = "Whole-brain Normalized Intensities", main = "Whole-brain: White Matter")
```
```{r ws_viz_wm, warning=FALSE, message=FALSE, echo = FALSE}
wm_ws_vals = mapply(function(t1, mask){
mask_vals(t1, mask == 3)
}, t1_ws_norm, tissues, SIMPLIFY = FALSE)
wm_ws_dens = lapply(wm_ws_vals, density)
plot_densities(wm_ws_dens,
xlab = "WhiteStripe Normalized Intensities", main = "White Stripe: White Matter")
```

## Conclusions
- Intensity normalization is an important step in any image analysis with more than one subject or time point to ensure comparability across images.
- White Stripe normalization may work better and have better interpretation than whole-brain normalization for subsequent lesion segmentation algorithms and analysis.
- Other intensity normalization methods that make intensites comparable across subjects for all tissues exist.
- RAVEL, which is an extension of WhiteStripe is one example [@fortin2016removing].
- Located at https://github.com/Jfortin1/RAVEL
- This was shown to have better comparability than histogram matching
## Website
http://johnmuschelli.com/imaging_in_r
## References {.smaller}