import mahotas as mh import numpy as np from matplotlib import pyplot as plt image=mh.imread(‘image/lena.jpg‘) image=mh.colors.rgb2gray(image) plt.gray() salt=np.random.random(image.shape)>.975 pepper=np.random.random(image.shape)>.975 image=mh.stretch(image) image=np.maximum(salt*170,image) image=np.minimum(pepper*30+image*(~pepper),image) plt.imshow(image) plt.show()
参考资料:
机器学习系统设计,p161
原文地址:http://blog.csdn.net/superdont/article/details/46351581