Red, green, and blue color alteration in images

We go further in this example to make an image that re-mixes the colors of the original in different proportions. The same code layout is used as in the previous example.

Getting ready

As before place the dusi_leo.png image into the folder /constr/pics1.

How to do it...

Execute the following code.

#image_color_manip_1.py
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import ImageEnhance, Image
im_1 = Image.open("/constr/pics1/dusi_leo_smlr_1.jpg")
# Split the image into individual bands
source = im_1.split()
R, G, B = 0, 1, 2
# Select regions where red is less than 100
red_band = source[R]
green_band = source[G]
blue_band = source[B]
# Process the red band: intensify red x 2
out_red = source[R].point(lambda i: i * 2.0)
# Process the green band: weaken by 20%
out_green = source[G].point(lambda i: i * 0.8)
# process the blue band: Eliminate all blue
out_blue = source[B].point(lambda i: i * 0.0)
# Make a new source of color band values
new_source = [out_red, out_green, out_blue]
# Add the three altered bands back together
im_2 = Image.merge(im_1.mode, new_source)
im_2.show()

How it works...

As before, the Image.split() function separates the three color bands of red, green, and blue from the original JPG image. In this case, the amounts of each red, green, and blue are 200%, 20%, and 0% of blue respectively.

There's more...

Altering the proportion of colors in existing pictures is a complex and subtle art and as we did in the previous chapters, in the next example we provide a recipe that uses slide controls to allow the user to use trial and error to achieve a desirable color mix on a band-separated image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.74.160