-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathnegative.py
More file actions
51 lines (34 loc) · 849 Bytes
/
negative.py
File metadata and controls
51 lines (34 loc) · 849 Bytes
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
import math
from copy import deepcopy
import cv2
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
def negative(r,g,b):
r = int(255-r)
g = int(255-g)
b = int(255-b)
return [r, g, b]
def setRGB(r,g,b):
r = int(r)
g = int(g)
b = int(b)
return [r, g, b]
img = Image.open('img/PeppersRGB.jpg')
img = np.asarray(img)
colorImg = deepcopy(img)
for i in range(len(img)):
for j in range(len(img[i])):
pixelR = int (img[i][j][0])
pixelG = int (img[i][j][1])
pixelB = int (img[i][j][2])
colorImg[i][j] = negative(pixelR,pixelG,pixelB)
plt.subplot(2,2,1)
plt.imshow(img)
plt.subplot(2,2,2)
plt.hist(img.ravel(),256,[0,256])
plt.subplot(2,2,3)
plt.imshow(colorImg)
plt.subplot(2,2,4)
plt.hist(colorImg.ravel(),256,[0,256])
plt.show()