-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathlogical_operator_image_processing.py
50 lines (36 loc) · 1.15 KB
/
logical_operator_image_processing.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
"""
Image Data Analysis Using Numpy & OpenCV
author: Mohammed Innat
email: [email protected]
website: https://iphton.github.io/iphton.github.io/
Please feel free to use and modify this, but keep the above information. Thanks!
"""
import imageio
import numpy as np
import matplotlib.pyplot as plt
pic = imageio.imread('F:/demo_1.jpg')
plt.figure(figsize = (10,10))
plt.imshow(pic)
plt.show()
low_pixel = pic < 20
# to ensure of it let's check if all values in low_pixel are True or not
if low_pixel.any() == True:
print(low_pixel.shape)
print(pic.shape)
print(low_pixel.shape)
'''
We generated that low value filter using a global comparison operator for
all the values less than 200. However, we can use this low_pixel array as an index
to set those low values to some specific values which may be higher than or lower
than the previous pixel value.
'''
# randomly choose a value
import random
# load the orginal image
pic = imageio.imread('F:/demo_1.jpg')
# set value randomly range from 25 to 225 - these value also randomly choosen
pic[low_pixel] = random.randint(25,225)
# display the image
plt.figure( figsize = (10,10))
plt.imshow(pic)
plt.show()