scipy图片处理(1)

from scipy import  io#保存与读写文件
import matplotlib.pyplot as plt
 
 
 

使用io.loadmat()读取数据

In [2]:
 
 
 
 
 
# io.loadmat('moon.mat',mdict={'moon':./moonlanding.png'})
# io.loadmat('./moonlanding.png')
 
 
 

读写图片使用scipy中的misc。imread()/imsave()

In [3]:
 
 
 
 
 
from scipy import misc
 
 
In [4]:
 
 
 
 
 
gilr=misc.imread('./cj0 (1).jpeg')
gilr
 
 
Out[4]:
array([[[204, 224, 222],
        [204, 224, 222],
        [204, 224, 222],
        ..., 
        [212, 163, 182],
        [214, 165, 184],
        [216, 167, 186]],

       [[203, 223, 221],
        [203, 223, 221],
        [204, 224, 222],
        ..., 
        [213, 164, 183],
        [215, 166, 185],
        [217, 168, 187]],

       [[203, 223, 221],
        [203, 223, 221],
        [204, 224, 222],
        ..., 
        [213, 164, 183],
        [215, 166, 185],
        [217, 168, 187]],

       ..., 
       [[227, 216, 224],
        [227, 216, 224],
        [227, 214, 223],
        ..., 
        [242, 112, 160],
        [241, 111, 159],
        [241, 111, 159]],

       [[227, 216, 224],
        [227, 216, 224],
        [227, 214, 223],
        ..., 
        [243, 113, 161],
        [243, 113, 161],
        [243, 113, 161]],

       [[227, 216, 224],
        [227, 216, 224],
        [227, 214, 223],
        ..., 
        [242, 114, 162],
        [244, 114, 162],
        [244, 114, 162]]], dtype=uint8)
In [5]:
 
 
 
 
 
# misc.imshow('./cj0 (1).jpeg')#这个方法只有在linux可以使用
 
 
In [6]:
 
 
 
 
 
import matplotlib.pyplot as plt
 
 
In [7]:
 
 
 
 
 
plt.imshow(gilr)
plt.show()
 
 
 
 

misc旋转,resize,imfilter(过滤切割图片)

In [8]:
 
 
 
 
 
g1=misc.imrotate(gilr,30)
 
 
In [9]:
 
 
 
 
 
plt.imshow(g1)
plt.show()
 
 
 
In [10]:
 
 
 
 
 
"""
size : int, float or tuple
    * int   - Percentage of current size.
    * float - Fraction of current size.
    * tuple - Size of the output image."""
g2=misc.imresize(g1,0.1)
plt.imshow(g2)
plt.show()
 
 
 
In [11]:
 
 
 
 
 
#滤波操作
'''
arr : ndarray
    The array of Image in which the filter is to be applied.
ftype : str
    The filter that has to be applied. Legal values are:
    'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more',
    'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'.'''
g3=misc.imfilter(gilr,'emboss')
plt.imshow(g3)
plt.show()
 
 
 
In [12]:
 
 
 
 
 
g3=misc.imfilter(gilr,'contour')
plt.imshow(g3)
plt.show()
 
 
 
 

 

你可能感兴趣的:(scipy图片处理(1))