I'm trying to extract some metrics from an histogram in R. For that I have an image in nifti and I plot the correspondent histogram. After that I want to extract mean, median, peak height, peak value and peak width. For that I have the following code:
img = readNIfTI("FA_skeleton_subj_0") #read nifti image
library(HistogramTools)
PlotRelativeFrequency(hist( x = img[ !img==0 ], xlim=c(0,0.8), breaks = seq(0,0.7,0.001)), xlab = "FA", main = "Histogram de FA") #plot relative frequency so I can compare between subjects
mean (img[ !img==0 ]) #!img==0 means that I don't want to count with zero voxels because they are background
median(img[ !img==0])
abline(v=median(img[ !img==0]),col="green")
abline(v=mean(img[ !img==0]),col="blue")
I would appreaciate some help to calculate the peak metrics (height, width and value). Thanks!
Here is an example on a random Gaussian sample:
Additionally, you may want to compute the mode of the sample, which can be done with one of the functions of the
modeest
package: