图片处理——灰度处理

图片灰度处理

三种方法

导包

import scipy.misc as misc

import matplotlib.pyplot as plt
%matplotlib inline

import numpy as np

导入图片

face = misc.face()
plt.imshow(face)

face.shape
Out:(768, 1024, 3)

法一:

# numpy聚合操作:一系列的方法
face2 = face.mean(axis = 2)
plt.imshow(face2,cmap = 'gray')

法二:

face
Out:
array([[[121, 112, 131],
        [138, 129, 148],
        [153, 144, 165],
        ...,

# 肉眼对颜色敏感度,不同:0.299,0.587,0.114
w = np.array([0.299,0.587,0.114])
face3 = np.dot(face,w)
plt.imshow(face3,cmap = 'gray')

猜你喜欢

转载自blog.csdn.net/Dorisi_H_n_q/article/details/82586016