# TypeError: 'tuple' object cannot be interpreted as an integer

I have an image (480,640,3) and I am trying to resize it to (150,150,1). Since my Keras model has been trained on images of shape (150,150,1), unfortunately I cannot seem to resize it using the PIL library. Any suggestions on how to fix this?

This is the code I am using right now:

The error is caused on the line image5.resize()

    stream.seek(0)
data = numpy.fromstring(stream.getvalue() , dtype = numpy.uint8)
image5 = cv.imdecode(data , 1)
print(image5.shape)
#cv.imwrite('uhhu.png',image5)
img = image5.resize((150,150,1 ), Image.ANTIALIAS)
cv.imwrite('hhh.png',img)
x = img_to_array(img)
x = x.reshape((1,) + x.shape)
x = x/255
x = numpy.array(x)
print(x.shape)
#print(score)

• I think you should specify exactly which line is causing the error. – Sajid Ahmed Apr 9 '19 at 11:05
• I'm not much of a Python user but what happens if you change (150,150,1) to (150,150)? I think you might need to change the depth separately. – PeterJ Apr 9 '19 at 12:12
• Initially it was 150,150 . Hence i changed it to 150,150,1 since that was the final shape i needed of the image – Zahid Ahmed Apr 9 '19 at 12:19
• Is your image in color? maybe you could try changing the depth by using RGB2Gray conversion – Pedro Henrique Monforte Apr 9 '19 at 18:31
• Pillow documentation (which is a fork of PIL) states that "A new PIL.Image.LANCZOS constant was added instead of ANTIALIAS.". You could try to check if this is true to PIL as well. – Pedro Henrique Monforte Apr 9 '19 at 18:38

img = cv.resize(image5 , (150,150))