擅长:python、mysql、java
<p>这是一个使用<code>scipy.ndimage</code>中的<a href="http://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.ndimage.interpolation.zoom.html" rel="nofollow noreferrer">zoom function</a>的超短解决方案。我用初始颜色(这里是随机的)定义一个2x2的RGB图像,并简单地将其缩放到256x256,<code>order=1</code>使插值线性化。代码如下:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
im=(np.random.rand(2,2,3)*255).astype(np.uint8)
from scipy.ndimage.interpolation import zoom
zoomed=zoom(im,(128,128,1),order=1)
plt.subplot(121)
plt.imshow(im,interpolation='nearest')
plt.subplot(122)
plt.imshow(zoomed,interpolation='nearest')
plt.show()
</code></pre>
<p>输出:</p>
<p><a href="https://i.stack.imgur.com/mMVYM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mMVYM.png" alt="output from the script"/></a></p>