pillow image TypeError: an integer is required (got type tuple)
<p>I am a bit lost as to why this is happening any help would be greatly appreciated. So I am trying to take the median value of images and create a new image from them, but when trying to make newpix take in the values of my red green and blue median pixel the error: </p>

<p>TypeError: an integer is required (got type tuple) </p>

<p>happens</p>

<pre><code>from PIL import Image, ImageChops,ImageDraw,ImageFilter
import math
import glob
import os.path
from os import  listdir;
import numpy


image_list = []

redPixels = []
greenPixels = []
bluePixels = []

for filename in glob.glob(r"C:\Users\Elias\Desktop\Proj1\images\*.png"):
    im = Image.open(filename)
    image_list.append(im)
im = Image.open(open(r"C:\Users\Elias\Desktop\Proj1\images\1.png",'rb'))
width, height = im.size
print(height)
print (width)

result = Image.new('RGB', (width,height))
newpix = result.load()
for x in range (width):
    for y in range (height):
        for z in (image_list):
            red  = z.getpixel((x,y))
            blue = z.getpixel((x,y))
            green = z.getpixel((x,y))

            redPixels.append(red)
            greenPixels.append(green)
            bluePixels.append(blue)
        red = sorted(redPixels)
        blue = sorted(bluePixels)
        green = sorted(greenPixels)

        mid = int( (len(image_list)+1)/2)-1

        newRed = redPixels[mid]
        newBlue = bluePixels[mid]
        newGreen = greenPixels[mid]
        newpix[x,y] = (newRed,newGreen,newBlue)

result.save("Stacked.png")
</code></pre>

<p>Problem is at the lines</p>

<pre><code>        red  = z.getpixel((x,y))
        blue = z.getpixel((x,y))
        green = z.getpixel((x,y))

        redPixels.append(red)
        greenPixels.append(green)
        bluePixels.append(blue)
</code></pre>

<p><code>red = z.getpixel((x,y))</code> will get all R,G,B data at x,y position, so it will be tuple like (255,255,255). Hence making changes to your code like below made it work:</p>

<pre><code>from PIL import Image, ImageChops,ImageDraw,ImageFilter
import math
import glob
import os.path
from os import  listdir;
import numpy


image_list = []

redPixels = []
greenPixels = []
bluePixels = []

for filename in glob.glob(r"C:\Users\Elias\Desktop\Proj1\images\*.png"):
    im = Image.open(filename)
    image_list.append(im)
im = Image.open(open(r"C:\Users\Elias\Desktop\Proj1\images\1.png",'rb'))
width, height = im.size
print(height)
print (width)

result = Image.new('RGB', (width,height))
newpix = result.load()
for x in range (width):
    for y in range (height):
        for z in (image_list):
            rgb  = z.getpixel((x,y))
            redPixels.append(rgb[0])
            greenPixels.append(rgb[1])
            bluePixels.append(rgb[2])
        red = sorted(redPixels)
        blue = sorted(bluePixels)
        green = sorted(greenPixels)

        mid = int( (len(image_list)+1)/2)-1
        newRed = redPixels[mid]
        newBlue = bluePixels[mid]
        newGreen = greenPixels[mid]

        newpix[x,y] = (newRed,newGreen,newBlue)

result.save("Stacked.png")
</code></pre>

python image python-3.x python-imaging-library pillow