首页 > 解决方案 > 填充轮廓图,同时覆盖在另一个图像上

问题描述

我在显示填充轮廓时遇到问题,而过度显示在另一张图像上。目前它向我显示未填充的轮廓。任何评论将不胜感激。

plt.imshow(t_image.detach().cpu().squeeze(), cmap='gray')
plt.contourf(filter_canny_predicted, colors='red') 
plt.contourf(filter_canny_mask, colors='green')
plt.autoscale() 
plt.show()

上面的代码片段将显示这个未填充轮廓的图像。 在此处输入图像描述

根据这里的答案

我将 set_rasterized 添加到片段中,但无法弄清楚轮廓和背景图像都消失了。这是我尝试使用 rasetrized 填充轮廓时的片段

  fig, (ax1) = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True)
ax1.imshow(t_image.detach().cpu().squeeze(), cmap='gray')
cs = ax1.contourf(filter_canny_predicted) 
css = ax1.contourf(filter_canny_mask)
ax1.axis('on')
ax1.autoscale()         
#ax1.tight_layout(pad=0.01, w_pad=0.002, h_pad=1)
for c in cs.collections:
    c.set_rasterized(True)
for cc in css.collections:
    cc.set_rasterized(True)
plt.show()   

它会产生这个图像,这不是我的要求。 在此处输入图像描述

为了澄清一个filter_canny_predicted是红色的,一个filter_canny_mask是黄色的。

在此处输入图像描述

标签: pythonmatplotlibcontourcontourf

解决方案


推荐阅读