scipy学习之(二)——io操作及其misc操作对图片的处理

SciPy有许多模块、类和函数,io子模块可用于从各种文件格式中读取数据和将数据写入各种文件格式。

from scipy import io

import numpy as np

生成数据

data = np.random.randint(0,100,size = (10,3))

保存数据:保存成mat格式的二进制文件

io.savemat("./data.mat",mdict = {"data":data})

加载数据

ret = io.loadmat("./data.mat")

读取生成的数据

ret["data"]

显示结果:

array([[90, 39, 31],
       [45,  8, 75],
       [75, 17,  5],
       [84, 62, 87],
       [30, 22, 32],
       [37, 15, 97],
       [67, 61, 95],
       [43, 13,  7],
       [27, 31, 40],
       [77, 25, 56]])

misc

是scipy中一个很杂的模块

介绍对图片进行过滤的方式

from scipy import misc
import matplotlib.pyplot as plt
%matplotlib inline

he = misc.imread("./timg1.jpg")

原图:

import warnings
warnings.filterwarnings("ignore")        #忽略警告问题

#imfilter中的一些属性如下列表,

类似高斯滤波的卷积操作

array = [ 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more','emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen']
he1 = misc.imfilter(he,array[0])

显示第二个属性样式
plt.imshow(he1)

猜你喜欢

转载自www.cnblogs.com/kuangkuangduangduang/p/10292183.html