
import numpy as npimport matplotlib.pyplot as plt# Construct a random 50x50 RGB image image = np.random.random((50, 50, 3))# Construct mask according to some condition;# in this case, select all pixels with a red value > 0.3mask = image[..., 0] > 0.3# Set all masked pixels to zeromasked = image.copy()masked[mask] = 0# Display original and masked images side-by-sidef, (ax0, ax1) = plt.subplots(1, 2)ax0.imshow(image)ax1.imshow(masked)plt.show()
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)