To understand some basic concepts, let's write code that just swaps the image band data.
Download the image
0165_3_15_COLOR_TWEAK.png
and rename it asCOLOR_TWEAK.png
.Type the following code:
1 import Image 2 3 img = Image.open( "C:\\images\\COLOR_TWEAK.png ") 4 img = img.convert('RGBA') 5 r, g, b, alpha = img.split() 6 img = Image.merge( "RGBA ", (g, r, b, alpha)) 7 img.show()
Let's analyze this code now. On line 2, the
Image
instance is created as usual. Then, we change themode
of the image toRGBA
.Next, the call to
Image.split()
creates separate instances ofImage
class, each containing a single band data. Thus, we have fourImage
instances—r
,g
,b
, andalpha
corresponding to red, green, and blue bands, and the alpha channel respectively.The code in line 6 does the main image processing. The first argument that...