ANTsX / ANTsR

R interface to the ANTs biomedical image processing library
https://antsx.github.io/ANTsR
Apache License 2.0
127 stars 35 forks source link

Calculating Grey Matter Volume using Eve atlas with ANTsR #293

Closed kmarvel54 closed 4 years ago

kmarvel54 commented 4 years ago

Hi ANTsR community,

I would like to calculate the grey matter volumes for specific regions of interest using Eve atlas (JHU_MNI_SS_WMPM_Type-I.nii.gz). The steps are as follows:

I have written the R script, which I borrowed from your course, and is as follows:

library(oro.dicom) library(oro.dicom) library(oro.nifti) library(ANTsR) library(extrantsr)

Sys.getenv("FSLDIR") library(fslr) library(scales) library(ggplot2) library(reshape2) library(plyr)

library(oro.dicom) library(oro.dicom) library(oro.nifti) library(ANTsR) library(extrantsr)

Sys.getenv("FSLDIR") library(fslr) library(scales) library(ggplot2) library(reshape2) library(plyr)

Registration of patient_T1.nii to a template (MNI) using ANTsR SyN registration mi <- antsImageRead("c1T1.nii.gz", dimension=3) # c1T1.nii.gz is the grey matter volume fi <- antsImageRead("MNI152_T1_1mm_brain.nii.gz", dimension=3) mytx <- antsRegistration(fixed = fi, moving = mi, typeofTransform = c("SyN"))

Read the atlas atlas <- readNIfTI("JHU_MNI_SS_WMPM_Type-I.nii.gz", reorient=FALSE)

Calculate regional grey matter volumes JHU_lut_df = read.table("JHU_MNI_SS_WMPM_Type-I_SlicerLUT.txt", stringsAsFactors=FALSE) JHU_lut_df = JHU_lut_df[, 1:2] colnames(JHU_lut_df) = c("index", "Label") JHU_lut_df$index = as.numeric(JHU_lut_df$index) JHU_lut_df[1:4,]

Reading in the Atlas JHU.img = atlas

Calculating Grey volumes by summing voxels in the "c1T1.nii.gz" Make a data frame with the index of the atlas and the value of the ROI at that voxel roi.df = data.frame(index = JHU.img[grey_matter_volumes > 0], roi = grey_matter_volumes[grey_matter_volumes > 0])

Obtain the number (sum) of voxels that have an roi value > 0 in the roi by the index of labels label_sums = ddply(roi.df, .(index), summarize, sum_roi = sum(roi), sum_roi_thresh = sum(roi > 0)) label_sums = merge(label_sums, JHU_lut_df, by="index")

voxel_resolution = voxres(JHU.img, units="cm") label_sums$volume = label_sums$sum_roi_thresh * voxel_resolution

Is there a utility in ANTsR that one can use to compute the grey matter volumes ?

Thanks, kate

stnava commented 4 years ago

I would recommend labelStats or labelGeometry

brian

On Thu, Jan 30, 2020 at 8:41 AM kmarvel54 notifications@github.com wrote:

Hi ANTsR community,

I would like to calculate the grey matter volumes for specific regions of interest using Eve atlas (JHU_MNI_SS_WMPM_Type-I.nii.gz). The steps are as follows:

I have written the R script, which I borrowed from your course, and is as follows:

library(oro.dicom) library(oro.dicom) library(oro.nifti) library(ANTsR) library(extrantsr)

Sys.getenv("FSLDIR") library(fslr) library(scales) library(ggplot2) library(reshape2) library(plyr)

library(oro.dicom) library(oro.dicom) library(oro.nifti) library(ANTsR) library(extrantsr)

Sys.getenv("FSLDIR") library(fslr) library(scales) library(ggplot2) library(reshape2) library(plyr)

Registration of patient_T1.nii to a template (MNI) using ANTsR SyN registration mi <- antsImageRead("c1T1.nii.gz", dimension=3) # c1T1.nii.gz is the grey matter volume fi <- antsImageRead("MNI152_T1_1mm_brain.nii.gz", dimension=3) mytx <- antsRegistration(fixed = fi, moving = mi, typeofTransform = c("SyN"))

Read the atlas atlas <- readNIfTI("JHU_MNI_SS_WMPM_Type-I.nii.gz", reorient=FALSE)

Calculate regional grey matter volumes JHU_lut_df = read.table("JHU_MNI_SS_WMPM_Type-I_SlicerLUT.txt", stringsAsFactors=FALSE) JHU_lut_df = JHU_lut_df[, 1:2] colnames(JHU_lut_df) = c("index", "Label") JHU_lut_df$index = as.numeric(JHU_lut_df$index) JHU_lut_df[1:4,]

Reading in the Atlas JHU.img = atlas

Calculating Grey volumes by summing voxels in the "c1T1.nii.gz" Make a data frame with the index of the atlas and the value of the ROI at that voxel roi.df = data.frame(index = JHU.img[grey_matter_volumes > 0], roi = grey_matter_volumes[grey_matter_volumes > 0])

Obtain the number (sum) of voxels that have an roi value > 0 in the roi by the index of labels label_sums = ddply(roi.df, .(index), summarize, sum_roi = sum(roi), sum_roi_thresh = sum(roi > 0)) label_sums = merge(label_sums, JHU_lut_df, by="index")

voxel_resolution = voxres(JHU.img, units="cm") label_sums$volume = label_sums$sum_roi_thresh * voxel_resolution

Is there a utility in ANTsR that one can use to compute the grey matter volumes ?

Thanks, kate

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsR/issues/293?email_source=notifications&email_token=AACPE7WBZQV4YFMYW57LAHDRALKJFA5CNFSM4KNWEY3KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IJ2ZUAA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPE7TAKT7L63SIZNFSDM3RALKJFANCNFSM4KNWEY3A .

kmarvel54 commented 4 years ago

Thanks Brian.

muschellij2 commented 4 years ago

Please do not spam 3-4 different outlets. You have already opened one issue, emailed me, and opened this. These are open source, free software. People will get back to you on their own time

On Thu, Jan 30, 2020 at 9:00 AM kmarvel54 notifications@github.com wrote:

Thanks Brian.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsR/issues/293?email_source=notifications&email_token=AAIGPLRKKRMCTXXTSLXULV3RALMONA5CNFSM4KNWEY3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKLCRBA#issuecomment-580266116, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLRXR6J4KF65WSP6XQDRALMONANCNFSM4KNWEY3A .

-- Best, John

cookpa commented 4 years ago

No need to remove, you can close your other issues but it would be helpful if you could first add a comment stating what solved your issue, so others can find the answer more quickly.

Thanks

On Jan 30, 2020, at 10:08 AM, moses1978 notifications@github.com wrote:



Hi John,

I am sorry John. Can I remove the others. I apologize for this.

Thanks, Kate

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/ANTsX/ANTsR/issues/293?email_source=notifications&email_token=AAEVJM4PHNJVLKRL4TA6HETRALUOHA5CNFSM4KNWEY3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKLKIJY#issuecomment-580297767, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEVJM6P6BYDHJGQYNTBCOLRALUOHANCNFSM4KNWEY3A.

kmarvel54 commented 4 years ago

Ok. Thanks Philip.

I have tried the first option, that is for labelStats. The usage of the labelStats is as follows:

segmented_grey_volume  <- antsImageRead("c1T1.nii.gz", dimension=3)
geom<-labelGeometryMeasures(seg)

This does not give the ROI found in the Eve atlas (JHU_MNI_SS_WMPM_Type-I.nii.gz), which has 176 ROI as in the look up table of Eve atlas:

https://github.com/muschellij2/Neurohacking_data/blob/master/Template/JHU_MNI_SS_WMPM_Type-I_SlicerLUT.txt

The second option requires you perform segmentation but I already have segmented grey volumes. Ultimately, I would like to have a results that looks like:

index       Label             volume (cm^3)

1       0    Background              534.1803759 2       1    Precentral_L              24.0800760 3       2    Precentral_R              25.0182769 4       3    Frontal_Sup_L            24.3499016 ; ; 177 177 ----------------- 5.38200

Thank you. Kate