Averaging multiple images in python -


i'm trying average 300 .tif images code :

import os, numpy, pil pil import image  # access png files in directory allfiles=os.listdir(os.getcwd()) imlist=[filename filename in allfiles if  filename[-4:] in[".tif",".tif"]]  # assuming images same size, dimensions of first image w,h = image.open(imlist[0]).size n = len(imlist)  # create numpy array of floats store average (assume rgb images) arr = numpy.zeros((h,w,3),numpy.float)  # build average pixel intensities, casting each image array of floats im in imlist:     imarr = numpy.array(image.open(im),dtype=numpy.float)     arr = arr+imarr/n  # round values in array , cast 16-bit integer arr = numpy.array(numpy.round(arr),dtype=numpy.uint16)  # generate, save , preview final image out = image.fromarray(arr,mode="rgb") out.save("average.tif") 

and gives me typeerror :

imarr = numpy.array(image.open(im),dtype=numpy.float) typeerror: float() argument must string or number, not 'tiffimagefile' 

i understand doesn't put tif image in numpy array (it doesn't work png images). should ? splitting each image r, g , b arrays average , merge seems memory consuming.

it should work is, checked right pil (pillow 2.9.0) , numpy 1.9.2.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -