Python Forum
grayscale image processing
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
grayscale image processing
#9
(Oct-25-2017, 06:25 AM)heiner55 Wrote:
from PIL import Image

img  = Image.open('grey.jpg')
width, height = img.size

for x in range(width):
    for y in range(height):
        pixel = img.getpixel((x,y))
        red   = pixel[0]
        green = pixel[1]
        blue  = pixel[2]
        grey  = (red + green + blue) // 3
        img.putpixel((x,y), (grey,grey,grey))

img.save("grey2.jpg", "jpeg")

hello, Thanks for reply. However, I don't understand your code that much. Why do you make grey=red+green+blue/3? What is this grey used for? And also, my aim is to find how many bright(greyscale value>200) pixels in a certain row which has most bright pixels.
Reply


Messages In This Thread
grayscale image processing - by zyb1003 - Oct-24-2017, 07:34 PM
RE: grayscale image processing - by Larz60+ - Oct-24-2017, 07:43 PM
RE: grayscale image processing - by zyb1003 - Oct-24-2017, 09:04 PM
RE: grayscale image processing - by Mekire - Oct-24-2017, 07:44 PM
RE: grayscale image processing - by Mekire - Oct-24-2017, 09:19 PM
RE: grayscale image processing - by zyb1003 - Oct-24-2017, 09:40 PM
RE: grayscale image processing - by Mekire - Oct-24-2017, 10:08 PM
RE: grayscale image processing - by heiner55 - Oct-25-2017, 06:25 AM
RE: grayscale image processing - by zyb1003 - Oct-25-2017, 07:07 PM
RE: grayscale image processing - by Mekire - Oct-25-2017, 07:12 PM
RE: grayscale image processing - by heiner55 - Oct-26-2017, 05:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pillow Image Processing matteusbeus 2 3,050 Nov-02-2017, 03:07 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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