回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个RGB彩色图像遮罩<code>mask_color</code>,形状(4,4,3)。如何快速地将所有黑色像素<code>[0,0,0]</code>转换为白色<code>[255,255,255]</code>,而不使用任何循环,不使用额外的包,最好是NumPy方式</p>
<pre><code>mask_color = np.array([
[
[0,0,0],
[128,0,255],
[0,0,0],
[0,0,0]
],
[
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0]
],
[
[0,0,0],
[50,128,0],
[0,0,0],
[0,0,0]
],
[
[0,0,0],
[0,0,0],
[245,108,60],
[0,0,0]
]
])
plt.imshow(mask_color)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/szmVG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/szmVG.png" alt="enter image description here"/></a></p>
<pre><code>white_bg_mask_color = # do something
plt.imshow(white_bg_mask_color)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/hoEcs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hoEcs.png" alt="enter image description here"/></a></p>