[split] Python Pillow - Photo Manipulation - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: [split] Python Pillow - Photo Manipulation (/thread-13368.html) |
[split] Python Pillow - Photo Manipulation - keegan_010 - Oct-11-2018 Hi, I am trying to use pillow for an online python photo manipulation course, I am only starting at the basics one of my tasks is to write a program converts an image to a sepia filter. It says that I have to convert it to grayscale and then add some adjustments. I have written some code, I have tried it on 2 images it gave me, however on only one certain image it gave me an error. My code is: from PIL import Image file = input("File name: ") img = Image.open(file) red,green,blue = img.split() for y in range(img.height): for x in range(img.width): r = red.getpixel((x,y)) g = green.getpixel((x,y)) b = blue.getpixel((x,y)) total = (r+g+b) avg = int((total/3)) red.putpixel((x,y),avg+30) green.putpixel((x,y),avg+10) blue.putpixel((x,y),avg-10) new_image = Image.merge('RGB', (red, green, blue)) new_image.save("output.png")When I try to do that certain image it says: Does anyone have any idea on how to fix this because it only does this error on this one certain picture.Thanks for your time. [split] Python Pillow - Photo Manipulation - Larz60+ - Oct-11-2018 this operation splits an image into four values, see: https://pillow.readthedocs.io/en/3.1.x/releasenotes/3.1.2.html?highlight=split There is also the following warning: Quote:If this buffer is smaller than expected, the jpeg2k unpacker functions will write outside the allocation and onto the heap, corrupting memory. |