-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_utils.py
55 lines (47 loc) · 1.5 KB
/
class_utils.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
51
52
53
54
55
# This is for ECE580: Intro to machine learning Spring 2020 in Duke
# This is translated to Python from show_chanWeights.m file provided by Prof. Li by 580 TAs
# import ext libs
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# from scipy.misc import imread # Make Sure you install the required packages like Pillow and scipy
def imgRead(fileName):
"""
load the input image into a matrix
:param fileName: name of the input file
:return: a matrix of the input image
Examples: imgIn = imgRead('lena.bmp')
"""
imgIn = plt.imread(fileName)
return imgIn
def imgShow(imgOut,title='Default Title'):
"""
show the image saved in a matrix
:param imgOut: a matrix containing the image to show
:return: None
"""
imgOut = np.uint8(imgOut)
plt.imshow(imgOut)
plt.title(title)
plt.show()
def imgSave(savedir,filename,filename_extension,img=[],cmap='gray',vmin=0,vmax=255):
img = np.uint8(img)
index = filename.find('.') # cut off the
plt.imsave(savedir + '/' +filename[:index] + '_' + filename_extension + '.png',img)
def imgRecover(imgIn, blkSize, numSample):
"""
Recover the input image from a small size samples
:param imgIn: input image
:param blkSize: block size
:param numSample: how many samples in each block
:return: recovered image
"""
##### Your Implementation here
return None
"""
if __name__ == '__main__':
a = imgRead('lena.bmp')
print(np.shape(a))
imgShow(a)
print(a)
"""