美文网首页
matplotlib显示mask标记的img / matplot

matplotlib显示mask标记的img / matplot

作者: Williamongh | 来源:发表于2019-06-04 21:34 被阅读0次
from matplotlib.colors import LinearSegmentedColormap
# get colormap
nalphas = 256    # 透明度alpha的级别
color_array = plt.get_cmap('Reds')(range(nalphas))
# change alpha values
color_array[:, -1] = np.linspace(0, 1, nalphas)
# color_array[-1,:] = [1, 0, 0, 1]    # 针对二值mask修改
# create a colormap object
Reds_alpha_objects = LinearSegmentedColormap.from_list(name='Reds_alpha', colors=color_array)
# register this new colormap with matplotlib
plt.register_cmap(cmap=Reds_alpha_objects)

# 显示原图像
plt.imshow(img[slice_index,:,:], cmap='gray')    
# 由于是二值mask,自定义的colormap只能保证label为0的位置是透明的,因此此处alpha设置为了0.3
plt.imshow(mask[slice_index,:,:], alpha=.3, cmap='Reds_alpha')    

相关文章

网友评论

      本文标题:matplotlib显示mask标记的img / matplot

      本文链接:https://www.haomeiwen.com/subject/vcfdxctx.html