DICOM stack mean value

Dear all, i am very new to R=)
Actually it is my first day here. I am trying to read the folder with several DICOM files and find a mean value in aech of the slice of the 3 D image
Here is what I wrote so far... But seems that I have only calculated mean value for the fist image in a stack... or not? I expected to get a vector not a value...
thank you in advance

library("oro.dicom")
current_folder <- "C:/NRA/DICOM_test"
DCM <- readDICOM(current_folder, verbose=TRUE)
# remove dicom header, leave just the image part
image<-DCM$img


# remove dicom header, leave just the image part
image<-DCM$img
#rewrite image (mode lyst as a matrix 512 by 512)
#matrix_512 <- matrix(unlist(image), byrow=TRUE, 512) 
matrix_512 <- matrix(unlist(image), 512, 512) 
# creat image
image(t(matrix_512), col=grey(0:64/64), axes=FALSE, xlab="", ylab="")


# 1step: find HU mean
for(i in 1:512)
{
  for(j in 1:512)
  {
    # meam
    M<- mean(matrix_512[,])
  }
  break
}
print(M)

Hi @sanata,

The DCM$img object returned from oro.dicom::readDICOM is a list of matrices, with one matrix per slice. So you can iterate over the slices and return a mean with the following code:

DCM <- readDICOM(current_folder, verbose=TRUE)
image<-DCM$img
purrr::map_dbl(image, mean)

This will return a vector with a length equal to the number of slices in the series. Hope this is helpful.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.