擅长:python、mysql、java
<p>您还可以使用<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.piecewise.html" rel="nofollow">numpy.piecewise</a>:</p>
<pre><code>In [11]: img32 = np.random.rand(800, 600).astype(np.float32)
In [12]: img_linear = np.piecewise(img32,
[img32 <= 0.04045, img32 > 0.04045],
[lambda v: v/12.92, lambda v: ((v + 0.055)/1.055)**2.4] )
In [13]: img_linear.shape
Out[13]: (800, 600)
In [14]: img_linear.dtype
Out[14]: dtype('float32')
</code></pre>