Python Forum
Python Pillow - Photo Manipulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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 which keeps only the blue channel from an image. Their hint is to loop through the pixels in the image and set the red and green values of each pixel to 0. The code I am trying is:
from PIL import Image

file = input("File name: ")
img = Image.open(file)

red, green, blue = img.split()

for y in range (red.height):
  for x in range (red.width):
    img.putpixel((x, y), 0)
    
for y in range (green.height):
  for x in range (green.width):
    img.putpixel((x, y), 0)
    
new_image = Image.merge ('RGB', (red, green, blue))

    
img.save("output.png")
However, after I do this, I only get an image that is totally black.

Can anybody help with this?

Thanks.
Reply


Messages In This Thread
Python Pillow - Photo Manipulation - by keegan_010 - Oct-10-2018, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  aoigram, pil Help with photo processing kolpac21 0 618 Aug-07-2023, 04:59 PM
Last Post: kolpac21
  Python re.sub text manipulation on matched contents before substituting xilex 2 2,171 May-19-2020, 05:42 AM
Last Post: xilex
  Add Photo in Python adninqasifa 4 6,148 Nov-26-2018, 06:06 PM
Last Post: adninqasifa
  Python Pillow I_Am_Groot 1 2,693 Oct-13-2018, 07:28 AM
Last Post: j.crater
  [split] Python Pillow - Photo Manipulation keegan_010 1 3,024 Oct-11-2018, 09:57 AM
Last Post: Larz60+
  Python Variable manipulation KirkmanJ 8 4,580 Aug-14-2018, 11:13 PM
Last Post: snippsat
  Combine images using Pillow and Python GMA 2 12,918 Jun-06-2018, 11:41 AM
Last Post: killerrex
  Closing an image opened by Pillow in Window Photo Viewer bigmit37 16 26,628 Aug-11-2017, 03:54 AM
Last Post: grahamnt
  Pillow _getexif for python 3 Larz60+ 2 23,346 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