Python Forum
[split] Python Pillow - Photo Manipulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Python Pillow - Photo Manipulation
#1
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:
Error:
Traceback (most recent call last): File "program.py", line 5, in <module> red,green,blue = img.split() ValueError: too many values to unpack (expected 3)
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.
Reply


Messages In This Thread
[split] Python Pillow - Photo Manipulation - by keegan_010 - Oct-11-2018, 09:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  aoigram, pil Help with photo processing kolpac21 0 596 Aug-07-2023, 04:59 PM
Last Post: kolpac21
  Python re.sub text manipulation on matched contents before substituting xilex 2 2,139 May-19-2020, 05:42 AM
Last Post: xilex
  Add Photo in Python adninqasifa 4 6,057 Nov-26-2018, 06:06 PM
Last Post: adninqasifa
  Python Pillow I_Am_Groot 1 2,677 Oct-13-2018, 07:28 AM
Last Post: j.crater
  Python Pillow - Photo Manipulation keegan_010 2 2,943 Oct-11-2018, 03:49 AM
Last Post: keegan_010
  Python Variable manipulation KirkmanJ 8 4,521 Aug-14-2018, 11:13 PM
Last Post: snippsat
  Combine images using Pillow and Python GMA 2 12,900 Jun-06-2018, 11:41 AM
Last Post: killerrex
  Closing an image opened by Pillow in Window Photo Viewer bigmit37 16 26,555 Aug-11-2017, 03:54 AM
Last Post: grahamnt
  Pillow _getexif for python 3 Larz60+ 2 23,219 Oct-01-2016, 10:25 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020