问题描述
我有两个数组:一个图像和一个蒙版。遮罩有不同的类别:0 到 4。我想在图像上绘制叠加层,但不显示“0”类别(只是不显示它,或者让它完全透明)。
这是我的代码:
# Plot
fig,ax = plt.subplots(2,4,dpi=300,figsize=(20,10))
cmap_mask = ListedColormap(['black','red','green','yellow'])
for index,channel in enumerate(channels):
# Top row without masks
ax[0,index].imshow(image[index,slice,:,:],cmap='gray')
ax[0,index].set_title(channel,fontweight='bold')
ax[0,index].get_xaxis().set_visible(False)
ax[0,index].get_yaxis().set_visible(False)
# Bottom row with masks
ax[1,cmap='gray')
ax[1,index].imshow(mask[slice,alpha=.7,cmap=cmap_mask)
ax[1,index].get_xaxis().set_visible(False)
ax[1,index].get_yaxis().set_visible(False)
我已经在这上面花了太长时间了。情节看起来不错,但我正在使背景变暗(由于黑色,但这是迄今为止我得到的最好的情节)。我尝试使用 np.ma.masked_where
,但我无法让它工作。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)