scipy.misc中的imresize

mjiansun發表於2017-03-02
>>> from scipy.misc import imresize
>>> import numpy as np
>>> a = np.random.random(25).reshape([5,5])
>>> a
array([[ 0.24677501,  0.08400788,  0.52535783,  0.98557437,  0.46538628],
       [ 0.14449665,  0.78652476,  0.02484598,  0.12847917,  0.17554679],
       [ 0.87219052,  0.3594529 ,  0.80304335,  0.17892899,  0.39732472],
       [ 0.80995837,  0.1105192 ,  0.89232289,  0.37695266,  0.34482325],
       [ 0.87255292,  0.64613089,  0.54023177,  0.7348253 ,  0.46107425]])
>>> b = imresize(a,(3,3))
>>> b
array([[ 68,  98, 116],
       [145, 126,  68],
       [169, 155, 122]], dtype=uint8)
>>> c = imresize(a,(4,4))
>>> c
array([[ 55,  78, 157, 123],
       [123, 126,  55,  57],
       [174, 121, 133,  86],
       [198, 142, 163, 122]], dtype=uint8)
>>> d = imresize(a,(5,5))
>>> d
array([[ 59,  16, 133, 255, 117],
       [ 32, 202,   0,  28,  40],
       [225,  89, 207,  41,  99],
       [208,  23, 230,  93,  85],
       [225, 165, 137, 188, 116]], dtype=uint8)


上面數值從小數變成幾百,這是因為需要講這些小數一一對應到0到255區間內

相關文章