Skip to content Skip to sidebar Skip to footer

Pillow Image Typeerror: An Integer Is Required (got Type Tuple)

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 tryi

Solution 1:

Problem is at the lines

        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 = z.getpixel((x,y)) 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:

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 inrange (width):
    for y inrange (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")

Post a Comment for "Pillow Image Typeerror: An Integer Is Required (got Type Tuple)"