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)# 均值中间填充 可以加权重
'''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)