插值
Bilinear interpolation would be order=1,
nearest is order=0,
and cubic is the default (order=3).
import numpy as np
import scipy.ndimage
x = np.arange(64).reshape(8,8)
print 'Original array:'
print x
print 'Resampled by a factor of 2 with nearest interpolation:'
print scipy.ndimage.zoom(x, 2, order=0)
print 'Resampled by a factor of 2 with bilinear interpolation:'
print scipy.ndimage.zoom(x, 2, order=1)
print 'Resampled by a factor of 2 with cubic interpolation:'
print scipy.ndimage.zoom(x, 2, order=3)
print 'Downsampled by a factor of 0.5 with default interpolation:'
print(scipy.ndimage.zoom(x, 0.5))
Original array:
array([[ 0, 1, 2, 3, 4, 5, 6, 7],
[ 8, 9, 10, 11, 12, 13, 14, 15],
[16, 17, 18, 19, 20, 21, 22, 23],
[24, 25, 26, 27, 28, 29, 30, 31],
[32, 33, 34, 35, 36, 37, 38, 39],
[40, 41, 42, 43, 44, 45, 46, 47],
[48, 49, 50, 51, 52, 53, 54, 55],
[56, 57, 58, 59, 60, 61, 62, 63]])
Resampled by a factor of 2 with nearest interpolation:
[[ 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]
[ 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]
[ 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15]
[ 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15]
[16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23]
[16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23]
[24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31]
[24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31]
[32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39]
[32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39]
[40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47]
[40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47]
[48 48 49 49 50 50 51 51 52 52 53 53 54 54 55 55]
[48 48 49 49 50 50 51 51 52 52 53 53 54 54 55 55]
[56 56 57 57 58 58 59 59 60 60 61 61 62 62 63 63]
[56 56 57 57 58 58 59 59 60 60 61 61 62 62 63 63]]
Resampled by a factor of 2 with bilinear interpolation:
[[ 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]
[ 4 4 5 5 6 6 7 7 7 8 8 9 9 10 10 11]
[ 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 14]
[11 12 12 13 13 14 14 14 15 15 16 16 17 17 18 18]
[15 15 16 16 17 17 18 18 19 19 20 20 21 21 21 22]
[19 19 20 20 21 21 21 22 22 23 23 24 24 25 25 26]
[22 23 23 24 24 25 25 26 26 27 27 28 28 28 29 29]
[26 27 27 28 28 28 29 29 30 30 31 31 32 32 33 33]
[30 30 31 31 32 32 33 33 34 34 35 35 35 36 36 37]
[34 34 35 35 35 36 36 37 37 38 38 39 39 40 40 41]
[37 38 38 39 39 40 40 41 41 42 42 42 43 43 44 44]
[41 42 42 42 43 43 44 44 45 45 46 46 47 47 48 48]
[45 45 46 46 47 47 48 48 49 49 49 50 50 51 51 52]
[49 49 49 50 50 51 51 52 52 53 53 54 54 55 55 56]
[52 53 53 54 54 55 55 56 56 56 57 57 58 58 59 59]
[56 56 57 57 58 58 59 59 60 60 61 61 62 62 63 63]]
Resampled by a factor of 2 with cubic interpolation:
[[ 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]
[ 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 9]
[ 7 8 8 9 9 10 10 11 11 12 12 12 13 13 14 14]
[12 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19]
[15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22]
[19 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26]
[22 23 23 24 24 25 25 26 26 27 27 27 28 28 29 29]
[26 26 27 28 28 28 29 29 30 30 31 31 32 32 33 33]
[30 30 31 31 32 32 33 33 34 34 35 35 35 36 37 37]
[34 34 35 35 36 36 36 37 37 38 38 39 39 40 40 41]
[37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 44]
[41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48]
[44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 51]
[49 49 50 50 51 51 51 52 52 53 53 54 54 55 55 56]
[54 54 54 55 55 56 56 57 57 58 58 59 59 60 60 61]
[56 56 57 57 58 58 59 59 60 60 61 61 62 62 63 63]]
Downsampled by a factor of 0.5 with default interpolation:
[[ 0 2 5 7]
[19 21 23 26]
[37 40 42 44]
[56 58 61 63]]
参考文献
Resampling a numpy array representing an image
机器学习入门必备的13张小抄