[R] TIF Mean pixel values

Mike Smith mike at hsm.org.uk
Wed Aug 10 19:00:48 CEST 2016


Im experimenting with mean pixel values for a series of images from a DSLR. I import 16-bit TIFs (RGB) from a directory using the following code, then loop through adding each TIF before dividing by the total number of files to give an image of mean pixel values. Some quick questions:

-having checked pixel values, this does what I expect it to do in that it creates the mean for each RGB layer in each image. It is pretty quick, but is a function that calculates both the mean and median pixel values for stacked layers like this?

-do all the calculations take place in 32 bit space? The tiff package lets me export as 16 bit tiffs, but is there anything that supports 32 bit tiffs??

-I get the following writeTIFF error (and the number has been scaled from the original 16 bit to 0-1):
"The input contains values outside the [0, 1] range - storage of such values is undefined"

-is there a more elegant/memory efficient way of doing this?!

Any help much appreciated!

best wishes


PS Two sample images here:

#Scan directory and store filenames in string, then count total files
files <- as.character(list.files(path="./mean/input/"))
n <- length(files)

#Use first TIF as loop file, then add all together
m_image_tiff <- readTIFF(paste("./mean/input/",files[1],sep=""))
for (i in 2:n){
  tiff <- readTIFF(paste("./mean/input/",files[i],sep=""))
  m_image_tiff <- (tiff+m_image_tiff)

#Calculate mean and write TIF
m_image_tiff <- (m_image_tiff/n)
Mike Smith

More information about the R-help mailing list