Python Forum
remove all color but red, then replace it with black
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
remove all color but red, then replace it with black
#6
I got pretty close. Perhaps you can tweek it a little further.
from PIL import Image
import numpy as np
img = Image.open('color_field.jpg')
width = img.size[0] 
height = img.size[1] 
for i in range(0,width):# process all pixels
	for j in range(0,height):
		data = img.getpixel((i,j))
		if data[0] < 235 :
			img.putpixel((i,j),(255, 255, 255))
		else :
			img.putpixel((i,j),(0, 0, 0))
img.show()
kucingkembar likes this post

Attached Files

Thumbnail(s)
       
Reply


Messages In This Thread
RE: remove all color but red, then replace it with black - by BashBedlam - Dec-26-2021, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why it gives me a black image and libpng warning: iCCP rickyw2777 1 591 Feb-16-2025, 08:26 PM
Last Post: rickyw2777
  Bright Black Screen Issue in Tkinter GUI Application rommy 2 1,273 Nov-29-2024, 10:50 PM
Last Post: woooee
  Black jack game simulation RoxaneParis1 3 1,506 Sep-11-2024, 06:57 AM
Last Post: indel635kanojia
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 3,823 Oct-25-2023, 09:09 AM
Last Post: codelab
  Checkbuttons always come up as black boxes regardless of the state kenwatts275 5 7,144 Jul-07-2020, 08:00 PM
Last Post: kenwatts275
  How to use nb-black python cde formatter ErnestTBass 3 8,874 Jun-04-2020, 03:51 PM
Last Post: ErnestTBass
  Finance: Black Scholes Model not working pwt 5 5,740 May-27-2020, 10:14 AM
Last Post: buran
  Because the emoji appears black and white at the exit ? nerd 3 6,897 Jan-28-2019, 11:34 PM
Last Post: nerd
  How to remove whitespace from a string when .replace and .strip do not work winnetrie 7 6,176 Jan-05-2019, 08:44 AM
Last Post: DeaD_EyE
  Search & Replace - Newlines Added After Replace dj99 3 4,463 Jul-22-2018, 01:42 PM
Last Post: buran

Forum Jump:

User Panel Messages

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