image - Average Picture of float Pictures Python -



image - Average Picture of float Pictures Python -

i want similar post: sample code

how can alter given code work float images in "tiff"- format?

this tried:

import os, numpy, pil pil import image # access png files in directory os.chdir("c://users//student///desktop//bilder//" ) print "current working dir : %s" % os.getcwd() allfiles=os.listdir(os.getcwd()) imlist=[filename filename in allfiles if filename[-5:] in [".tiff",".tiff"]] #imlist=[filename filename in allfiles] # 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,1),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+=imarr/n # round values in array , cast 8-bit integer arr=numpy.array(numpy.round(arr),dtype=numpy.uint8) # generate, save , preview final image out=image.fromarray(arr,mode="f") out.save("average.tiff") out.show()

wich produces error:

file "c:\users\student\im_average.py", line 25, in <module> arr+=imarr/n valueerror: non-broadcastable output operand shape (250,250,1) doesn't match broadcast shape (250,250,250)

i not familiar numpy arrays, help welcome.

doing imarr/n inplace , convert dtype integer of array. so, utilize n=float(n)

refer http://docs.scipy.org/doc/numpy/user/basics.indexing.html#assigning-values-to-indexed-arrays

please note assignments may result in changes if assigning higher types lower types (like floats ints) or exceptions (assigning complex floats or ints).

python image numpy python-imaging-library

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -