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
#2
Hello,
I checked the docs for putpixel() here, and I believe that instead of 0 (which probably means black), you should place a RGB tuple, so (0, 0, blue_value).

By the way, may I ask what is the course you are taking? Thanks.
Reply
#3
Hi j.crater,
Thanks for your help but I figured out where I went wrong. The course is on a website called Grok, and the course is called Investigating Images. Although you have to pay for the course, but I get it free as an education Queensland student.
Thanks.
Reply


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