-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgray_level_processing.py
More file actions
91 lines (53 loc) · 1.33 KB
/
Copy pathgray_level_processing.py
File metadata and controls
91 lines (53 loc) · 1.33 KB
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
84
85
86
87
88
# coding: utf-8
# In[1]:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
# In[2]:
ls
# In[3]:
import matplotlib.pyplot as plt
import numpy as np
img_1=plt.imread("a1.jpg")
# In[4]:
img_1.ndim,img_1.shape
# In[5]:
plt.imshow(img_1)
plt.show()
# In[6]:
def convertRGBPixelToGrayLevel(RGB_Pixel):
return RGB_Pixel[0]/3 + RGB_Pixel[1]/3 + RGB_Pixel[2]/3
# In[7]:
convertRGBPixelToGrayLevel([2,8,9])
# In[11]:
img_2=np.zeros((img_1.shape[0],img_1.shape[1]))
img_2.shape
# In[13]:
for i in range (img_1.shape[0]):
for j in range (img_1.shape[1]):
img_2[i,j]=convertRGBPixelToGrayLevel(img_1[i,j,:])
# In[18]:
plt.subplot(1,2,1)
plt.imshow(img_1)
plt.subplot(1,2,2)
plt.imshow(img_2, cmap='gray')
plt.show()
# In[20]:
import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import imsave
def convertRGB_to_GrayLevel(image_1):
img_1=plt.imread(image_1)
img_2=np.zeros((img_1.shape[0],img_1.shape[1]))
for i in range(img_1.shape[0]):
for j in range(img_1.shape[1]):
img_2[i,j]=img_1[i,j,0]/3 + img_1[i,j,1]/3 + img_1[i,j,2]/3
imsave(image_1 + "gray.jpg", img_2)
plt.subplot(1,2,1)
plt.imshow(img_1)
plt.subplot(1,2,2)
plt.imshow(img_2, cmap='gray')
plt.show()
convertRGB_to_GrayLevel("test_10.jpg")
# In[ ]: