0
点赞
收藏
分享

微信扫一扫

在图片上画出mask和pred

画出论文中《Variance-aware attention U-Net for multi-organ segmentation》的图1,也就是在原图上画出mask和pred的位置。
在这里插入图片描述
新建一个文件夹
在这里插入图片描述
然后运行代码:

import cv2
import os
from os.path import splitext

####第一次:把GT(绿)放在原图上
###第二次:把pre(红)放在第一次输出的图片上
###需要保证预测输出的图片和原图大小一样(256*256)


if __name__== '__main__':
    # image = cv2.imread('./image/02_4.png')    ###在原图上画masks轮廓, 绿
    # mask = cv2.imread('./mask/02_4.png')
    image = cv2.imread('./first/02_4.png')  # 在原图上画masks轮廓, 红
    mask = cv2.imread('./mask/02_4.jpg')
    print(image.shape)
    print(mask.shape)
    newwidth = 256
    newheigh = 256
    res_mask = cv2.resize(mask,(newwidth,newheigh))

    print(res_mask.shape)
    # file_name = splitext(cur_dir_files[i])[0] + "." + "tif"

    # binary_mask = cv2.Canny(mask, 30, 100)  # Canny边缘检测算法
    binary_mask = cv2.Canny(res_mask, 30, 100)  # Canny边缘检测算法
    mask_contour = cv2.findContours(binary_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)  # 获取轮廓
    cv2.drawContours(image, mask_contour[0], -1, (0, 0, 255), 1)  # 在原图上画masks轮廓;红
    # cv2.drawContours(image, mask_contour[0], -1, (0, 255, 0), 1)  # 在原图上画masks轮廓;绿
    # cv2.imwrite('./first/' + './02_4.png', image)
    cv2.imwrite('./second/' + './02_4.png', image)


举报

相关推荐

0 条评论