Python Forum
Brightening an image by changing pixel value (PIL image import) grok learning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Brightening an image by changing pixel value (PIL image import) grok learning
#3
(Dec-06-2018, 03:21 PM)j.crater Wrote: Hello

    pixel = img.getpixel((x,y))
value = img.getpixel((x,y))
What is the purpose of these seemingly same operations, why doubled?

You get all x and y pixels in the inner for loop, but you set the pixel value (+50) outside of that loop. So I would guess it only changes the last pixel it iterates over, when the for loops exit. Instead you should do that inside the loop.

Hi, thank you for your help~

When removing the line for inner for loop I get error messages, same goes for it I added the 50 and then remove it for the outside of the loop. Vice versa gives me errors as well. Leaving them both gives me no error besides not brightening the image.

I decided to just leave that code alone since it isn't doing anything. I tried something a little different with the code here;

from PIL import Image
file = input("File name: ")
img = Image.open(file)
width, height = img.size
value = img.getpixel(img.size)
img.putpixel(value + 50)
img.save("output.png")
I get this error however;
"Traceback (most recent call last):
File "program.py", line 5, in <module>
value = img.getpixel(img.size)
File "/opt/python-3.6/lib/python3.6/site-packages/PIL/Image.py", line 1227, in getpixel
return self.im.getpixel(xy)
IndexError: image index out of range"

I've never seen it before so I'm not sure what it means? I feel like I'm just making things worse at this point.
Reply


Messages In This Thread
RE: Brightening an image by changing pixel value (PIL image import) grok learning - by Turkejive - Dec-07-2018, 01:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Image processing MNO 0 6,500 Apr-27-2022, 06:34 AM
Last Post: MNO
  how to save an image on python perrieS 1 1,601 Dec-13-2020, 11:54 PM
Last Post: Larz60+
  What does image.setMask do? A01 3 2,198 Dec-08-2020, 07:06 AM
Last Post: ndc85430
  Image data cannot be converted to float rakeshd3 1 7,032 Mar-17-2020, 08:01 AM
Last Post: buran
  Convert text from an image to a text file Evil_Patrick 5 4,217 Jul-30-2019, 07:57 PM
Last Post: DeaD_EyE
  Find the centroids of all the stars in a fits image TaikiBessho 2 2,576 Jul-27-2019, 07:18 AM
Last Post: TaikiBessho
  code to retrieve an image gave me an error matthew18 1 1,795 Apr-04-2019, 05:38 PM
Last Post: nilamo
  Changing "import numpy as np" to "from numpy import" ClintWestwood 4 6,314 Nov-28-2018, 06:45 AM
Last Post: nilamo
  Image Puzzle Digitalchemist 6 7,219 Jun-05-2017, 07:56 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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