-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing_list.py
More file actions
executable file
·98 lines (75 loc) · 2.72 KB
/
Copy pathprocessing_list.py
File metadata and controls
executable file
·98 lines (75 loc) · 2.72 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
89
90
91
92
93
94
95
96
from math import cos, log, sin
from PIL import Image
import numpy as np
# Thresholding
def thresholding(input_image, color_depth, val):
if color_depth != 25:
input_image = input_image.convert('RGB')
T = val
output_image = Image.new(
'RGB', (input_image.size[0], input_image.size[1]))
pixels = output_image.load()
for i in range(output_image.size[0]):
for j in range(output_image.size[1]):
r, g, b = input_image.getpixel((i, j))
if r and g and b < T:
pixels[i, j] = (0, 0, 0)
else:
pixels[i, j] = (255, 255, 255)
if color_depth == 1:
output_image = output_image.convert("1")
elif color_depth == 8:
output_image = output_image.convert("L")
else:
output_image = output_image.convert("RGB")
return output_image
#Negative
def negative(input_image, color_depth):
if color_depth != 25:
input_image = input_image.convert("RGB")
input_pixels = input_image.load()
output_image = Image.new("RGB", input_image.size)
output_pixels = output_image.load()
horizontal_size = output_image.size[0]
vertical_size = output_image.size[1]
for x in range(horizontal_size):
for y in range(vertical_size):
R = 255 - input_pixels[x, y][0]
G = 255 - input_pixels[x, y][1]
B = 255 - input_pixels[x, y][2]
output_pixels[x, y] = (R, G, B)
if color_depth == 1:
output_image = output_image.convert("1")
elif color_depth == 8:
output_image = output_image.convert("L")
else:
output_image = output_image.convert("RGB")
return output_image
#Brightness
def clipping(intensity):
if intensity < 0:
return 0
if intensity > 255:
return 255
return intensity
def brightness(input_image, color_depth, enlightenment_value):
if color_depth != 25:
input_image = input_image.convert("RGB")
input_pixels = input_image.load()
output_image = Image.new("RGB", input_image.size)
output_pixels = output_image.load()
horizontal_size = output_image.size[0]
vertical_size = output_image.size[1]
for x in range(horizontal_size):
for y in range(vertical_size):
R = clipping(input_pixels[x, y][0] + enlightenment_value)
G = clipping(input_pixels[x, y][1] + enlightenment_value)
B = clipping(input_pixels[x, y][2] + enlightenment_value)
output_pixels[x, y] = (R, G, B)
if color_depth == 1:
output_image = output_image.convert("1")
elif color_depth == 8:
output_image = output_image.convert("L")
else:
output_image = output_image.convert("RGB")
return output_image