-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiom.py
38 lines (23 loc) · 770 Bytes
/
iom.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
from skimage import io
import scipy.io
import numpy as np
def read_image(path, gray=False):
image = io.imread(path, as_grey=gray).astype(np.float32)
image = image / 255.
return image
def write_image(path, image):
# if len(image.shape) != 2:
image = image * 255.
image = image.astype(np.uint8)
io.imsave(path, image)
def dump_mat(path, dict):
if path is not None:
scipy.io.savemat(path, dict)
if __name__ == '__main__':
import matplotlib.pyplot as plt
image = read_image('https://img-9gag-fun.9cache.com/photo/am7ppD2_700b.jpg')
print(image.shape)
print('MAX: {} | MIN: {}'.format(np.max(image), np.min(image)))
write_image('test.png', image)
plt.imshow(np.squeeze(image))
plt.show()