!重要提醒:非课后答案,仅代表本菜需要理解记忆的一些知识点,随机更新相关想法思考,欢迎讨论, 斜体加粗为尚未查询或解决的问题
鉴于本菜狗子当初找cs131资源花了不少功夫,终于找到了可下载的课件,版本是2017 fall,作业为python版本的,之前的都是matlab版本,作业大家就随缘查找吧。如果本文对您学习有一点点帮助,不需要赞赏,请在学习之后留下一些您的想法与感悟,万分感谢!
斯坦福CS131课程课件下载链接:http://vision.stanford.edu/teaching/cs131_fall1718/files/
祝各位学业顺利!
导入函数
-
已编辑好的函数脚本导入 ‘import linalg as *’ 这里的*是什么意思?
-
为了在jupyter notebook页面内显示图片而不是新开一个窗口
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
Linear Algebra Review
1. 生成矩阵与向量
M = np.arange(1, 13).reshape((4, 3)) #这里发现reshape后面一个括号也可以?
a = np.array([1, 1, 0])
b = np.array([[-1], [2], [5]]) #列向量两层括号
- 注意点乘,矩阵乘法与 * 之间的联系与区别
#感觉用np.dot起到一样的效果
out = np.matmul(vector1.T, vector2) * np.matmul(M, vector1)
- SVD分解和特征值特征向量分解
u, s, v = svd(matrix)
w,v = np.linalg.eig(matrix)
svd分解后为了节省储存空间s分量以行向量储存,与eigenalue一样,singular value都是从大到小排的。
Image Manipulation
1. 读取图片
这里还没有配置python-opencv,所以用的都是一些skimage和PIL函数?这个还不太懂,以后过来补充
def display(img):
# Show image
plt.imshow(img)
plt.axis('off')
plt.show()
image1 = load(image1_path) # out = io.imread(image_path)
image2 = load(image2_path)
display(image1)
display(image2)
2. 改变图像像素值
out = 0.5 * np.square(image) #可以试试0.5 * image ** 2
3. 转成灰度图
out = np.sum(image, axis=2) / 3
sum中的axis的值的含义是什么呢?
4. 颜色通道
4.1. RGB
color = {'r': 0, 'g': 1, 'b': 2}
image = np.array(image)
image[..., color[channel.lower()]] = 0
#image[:, :, color[channel.lower()]] = 0 也行吧
4.2. LAB
lab = color.rgb2lab(image)
color_dict = {'l': 0, 'a': 1, 'b': 2}
lab = (lab + np.abs(np.min(lab)))
lab = lab / np.max(lab)
lab[:,:,color_dict[channel.lower()]] = 0
out = lab
4.3. HSV
hsv = color.rgb2hsv(image)
color_dict = {'h': 0, 's': 1, 'v': 2}
hsv[:, :, color_dict[channel.lower()]] = 0
5. 图片混合
image1 = rgb_decomposition(image1, channel1)
image2 = rgb_decomposition(image2, channel2)
out = np.zeros_like(image1)
out[:, 0:image1.shape[1]/2] = image1[:, 0:image1.shape[1]/2]
out[:, image1.shape[1] / 2:] = image2[:, image1.shape[1] / 2:]
最近对CIE-XYZ,LAB等颜色通道很头疼,理解不深刻,望各位大佬不吝赐教。
网友评论