[58c332]: / RadETL / R / imageOrientationConceptId_ImageTable.R

Download this file

61 lines (59 with data), 2.5 kB

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#' 'imageOrientationConceptId'
#'
#' imageOrientationConceptId function will represent direction of each image
#'
#'
#' @param DICOMList you can put it like this and then run the function : DICOMList<-DICOMHeaderList(DICOMFolderPath)
#' @import dplyr
#' @importFrom magrittr "%>%"
#'
#'
#' @return A list containing direction of each DICOM image
#' @examples
#' DICOMList<-DICOMHeaderList(DICOMFolderPath)
#' imageOrientationConceptId(DICOMList)
#' @export
imageOrientationConceptId<-function(DICOMList){
imageOrientationConceptId<-lapply(DICOMList, function(x){
imageOrientationConceptIdDf<-x[[1]] %>% dplyr::filter(name %in% c('PatientOrientation', 'ImageType', 'SeriesDescription', 'StudyDescription', 'BodyPartExamined')) %>% dplyr::select(value)
colnames(imageOrientationConceptIdDf)<-'imageOrientationConceptId'
imageOrientationConceptIdDf<-sapply(imageOrientationConceptIdDf, function(x){
if(grepl('chest', tolower(imageOrientationConceptIdDf))==T&grepl('P F', imageOrientationConceptIdDf)==T){
return('43591')
}
else if(grepl('chest', tolower(imageOrientationConceptIdDf))==T&grepl('L F', imageOrientationConceptIdDf)==T){
return('43594')
}
else if(grepl('chest', tolower(imageOrientationConceptIdDf))==T){
return('43594')
}
else if(grepl('axial', tolower(imageOrientationConceptIdDf))==T){
return('10514')
}
else if(grepl('AX', imageOrientationConceptIdDf)==T){
return('10514')
}
else if(grepl('DW', imageOrientationConceptIdDf)==T){
return('10514')
}
else if(grepl('FLAIR', imageOrientationConceptIdDf)==T){
return('10514')
}
else if(grepl('Apparent', imageOrientationConceptIdDf)==T){
return('10514')
}
else if(grepl('SA', imageOrientationConceptIdDf)==T){
return('sagittal')
}
else{
return('others')
}
})
imageOrientationConceptIdDf<-as.data.frame(imageOrientationConceptIdDf)
rownames(imageOrientationConceptIdDf)<-c()
colnames(imageOrientationConceptIdDf)<-c('imageOrientationConceptId')
return(imageOrientationConceptIdDf)
})
imageOrientationConceptId<-do.call(rbind, imageOrientationConceptId)
return(imageOrientationConceptId)
}