ndimage
start
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
使用中值滤波,高斯滤波处理图片
moon = plt.imread('./moonlanding.png')

plt.imshow(moon,cmap='gray')
'''sigma : scalar or sequence of scalars
Standard deviation for Gaussian kernel. The standard
deviations of the Gaussian filter are given for each axis as a
sequence, or as a single number, in which case it is equal for
all axes.'''
moon2 = ndimage.gaussian_filter(moon,sigma=1)
plt.imshow(moon2,cmap='gray')
moon3 = ndimage.median_filter(moon,size = 5)
plt.imshow(moon3,cmap='gray')
图片在画布上的移动
cat = ndimage.imread('./cat.jpg')
plt.imshow(cat)

cat2 = ndimage.shift(cat,shift=[0,300,0])
plt.imshow(cat2)
- 将图片向右移动
- shift 参数一上下移动;参数二左右移动;参数三改变颜色,即,分别对应三维
'''mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
The `mode` parameter determines how the input array is extended
when the filter overlaps a border. Default is 'reflect'. Behavior
for each valid value is as follows:
'reflect' (`d c b a | a b c d | d c b a`)
The input is extended by reflecting about the edge of the last
pixel.
'constant' (`k k k k | a b c d | k k k k`)
The input is extended by filling all values beyond the edge with
the same constant value, defined by the `cval` parameter.
'nearest' (`a a a a | a b c d | d d d d`)
The input is extended by replicating the last pixel.
'mirror' (`d c b | a b c d | c b a`)
The input is extended by reflecting about the center of the last
pixel.
'wrap' (`a b c d | a b c d | a b c d`)
The input is extended by wrapping around to the opposite edge.'''
cat2 = ndimage.shift(cat,shift=[0,360,0],mode='reflect')
plt.imshow(cat2)
cat3 = ndimage.rotate(cat,60)
plt.imshow(cat3)
cat3 = ndimage.zoom(cat,zoom=[0.5,1.5,1])
plt.imshow(cat3)