1
+ # Giving Filters to images
2
+ # Individual Channels
3
+
4
+ from PIL import Image
5
+
6
+ img = Image .open ("226.jpg" )
7
+ print (img .mode ) # RGB is the mode
8
+
9
+ r , g , b = img .split () # It returns a tuple of 3 images i.e, the amount of red, green and blue in the image
10
+
11
+ r .show ()
12
+ g .show ()
13
+ b .show ()
14
+
15
+ # Merging effect -> merging the individual channels of R,G,B to create a filter
16
+
17
+ img1 = Image .merge ("RGB" , (r , g , b )) # It takes in the mode and the colours
18
+ # In the above case, it will print the same image
19
+
20
+ img2 = Image .merge ("RGB" , (b , g , r ))
21
+ img2 .show ()
22
+
23
+ img3 = Image .merge ("RGB" , (g , r , b ))
24
+ img3 .show ()
25
+
26
+ img4 = Image .merge ("RGB" , (b , g , b ))
27
+ img4 .show ()
28
+
29
+ # It just takes in the amount of R,G,B in the given given format(RGB), but different permutations give different results
30
+ # Likewise we can use any other permutations, to form different filters of the images
31
+
32
+ # Double Exposure:
33
+ # to use this, the two images must be of the same size
34
+
35
+ new_img1 = Image .open ("1_Earth.jpg" )
36
+ new_img2 = Image .open ("1_mario.jpg" )
37
+
38
+ r1 , b1 , g1 = new_img1 .split ()
39
+ r2 , b2 , g2 = new_img2 .split ()
40
+
41
+ final_image = Image .merge ("RGB" , (r1 , b2 , g1 ))
42
+ final_image .show ()
0 commit comments