I am trying to change the RGB values ββin a photograph using a Python image library. I use the Image.point function and it does what I want, except that I want to be able to implement another function in the values ββof R and G. Does anyone know how I can do this?
Thanks!
You are better off using numpy in addition to PIL to do the math of individual bands of the image.
numpy
As a contrived example that should not look good in any way:
import Image import numpy as np im = Image.open('snapshot.jpg') # In this case, it a 3-band (red, green, blue) image # so we'll unpack the bands into 3 separate 2D arrays. r, g, b = np.array(im).T # Let make an alpha (transparency) band based on where blue is < 100 a = np.zeros_like(b) a[b < 100] = 255 # Random math... This isn't meant to look good... # Keep in mind that these are unsigned 8-bit integers, and will overflow. # You may want to convert to floats for some calculations. r = (b + g) * 5 # Put things back together and save the result... im = Image.fromarray(np.dstack([item.T for item in (r,g,b,a)])) im.save('output.png')
Input
Exit
Source: https://habr.com/ru/post/917061/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/917056/opengl-draw-pixels-to-screen&usg=ALkJrhgt3moHdAlTj5UFhRbcqGKt3RmmZwEffectively retrieve ice_cube charts for a given time period - ruby-on-railsWhat is the proper way to initiate network communication based on broadcast reception? - androidHighcharts does not display all categories - highchartsThis is there the equivalent of size_t in llvm - cPreserve space when hiding text field in rdlc file - visibilityDisturbing text on iPhone - css30 million rows in MySQL - mysqlWait for a few callbacks - multithreadingIs there a good way to check if a row contains at least one row from an array of strings? - stringAll Articles