-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageProcessing.py
83 lines (73 loc) · 2.24 KB
/
ImageProcessing.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
initial_image = Image.open("Tajmahal.jpeg")
image = np.array(Image.open('Tajmahal.jpeg'))
def display():
initial_image.show()
def brightness():
b=int(input("Enter the value for brightness: "))
bright = image + b
Image.fromarray(bright).save('Tajmahal_b.jpeg')
brightImage = Image.open("Tajmahal_b.jpeg")
brightImage.show()
def diffence():
orImage = np.array(Image.open("Tajmahal.jpeg"))
brightened = orImage + 100
Image.fromarray(brightened).save('Tajmahal_brightened.jpeg')
brArray = np.array(Image.open('Tajmahal_brightened.jpeg'))
diffArr = brightened - orImage
Image.fromarray(diffArr).show()
#imageDifference.show()
def negative():
bright = 255 - image
Image.fromarray(bright).save('Tajmahal_i.jpeg')
negativeImage = Image.open("Tajmahal_i.jpeg")
negativeImage.show()
def threshold():
th=int(input("Enter Threshold Value"))
im = np.array(Image.open('Tajmahal.jpeg').resize((200,200)))
w=im
for i in range(0,200):
for j in range(0, 200):
for k in range(0,3):
if(im[i][j][k] > th):
w[i][j][k] = 1
else:
w[i][j][k] = 0
Image.fromarray(w).save('Tajmahal_t.jpeg')
t= Image.open("Tajmahal_t.jpeg")
t.show()
def histogram():
histo= np.array(Image.open('Tajmahal.jpeg').convert('L'))
plt.hist(histo)
plt.show()
def image_processing():
choice=0
while(choice!=7):
print("Menu:")
print("1.Display Image")
print("2.Change Brightness ")
print("3.Difference between two images")
print("4.Negative Image")
print("5.Histogram")
print("6.Threshold")
print("7.Exit")
choice=int(input("Enter your choice: "))
if(choice==1):
display()
elif(choice==2):
brightness()
elif(choice==3):
diffence()
elif(choice==4):
negative()
elif(choice==5):
histogram()
elif(choice==6):
threshold()
elif(choice==7):
print("Terminating..")
else:
print("\nInvalid choice")
image_processing()