-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathimage.py
67 lines (47 loc) · 1.54 KB
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# author: Somsubhra Bairi (201101056)
# Draws an image of chessboard and saves it
# Also applies an emboss filter to it and saves it
# Images are saved in out.jpg and out1.jpg
# Python imports
from PIL import Image
from PIL import ImageFilter
import webbrowser
# The main function
def main():
# Create a new image of size 800x800
img = Image.new('RGB', (800, 800), "black")
# Load the pixels
pixels = img.load()
# The output filename
filename = "out.jpg"
# The second output image filename
filename1 = "out1.jpg"
filename2 = "out2.jpg"
# Iterate through rows of image
for i in range(img.size[0]):
row = int(i / 100)
# Iterate through the columns of image
for j in range(img.size[1]):
col = int(j / 100)
# Draw the pixel white based on its location to create a chessboard
if col % 2 == 0 and row % 2 == 0 or col % 2 != 0 and row % 2 != 0:
pixels[i, j] = (255, 255, 255)
# Save the image
img.save(filename)
# Apply emboss filter
img1 = img.filter(ImageFilter.EMBOSS)
# Save the embossed image
img1.save(filename1)
# Apply edge detection filter
img2 = img.filter(ImageFilter.FIND_EDGES)
# Save the edge detected image
img2.save(filename2)
# Open embossed image in image browser
webbrowser.open(filename1)
# Open edge detected image
webbrowser.open(filename2)
# Open the image in image browser
webbrowser.open(filename)
# Run the main function
if __name__ == '__main__':
main()