import cv2
import numpy as np
import os
import random
from PIL import Image
import matplotlib.pyplot as plt
# 将mask绘制在原图
def draw_image(im, ms, brg, opacity):
image_mask = im.copy()
contours, _ = cv2.findContours(ms, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) # 查找轮廓
image_mask = cv2.drawContours(image_mask, contours, -1, (0, 255, 0), 2) # 绘制边界
image_mask = cv2.fillPoly(image_mask, contours, color=brg) # 填充
img_bgr = cv2.addWeighted(im, opacity, image_mask, 1 - opacity, 0)
return im, ms, img_bgr[:, :, ::-1]
def main(imagePath, labelPath, bgr, opacity):
image = np.array(Image.open(imagePath).convert('RGB'))
label = np.array(Image.open(labelPath).convert('L'))
a, b, c = draw_image(image, label, bgr, opacity)
plt.figure(figsize=(12, 8))
for index, i in enumerate((a, b, c)):
plt.subplot(1, 3, index + 1)
plt.imshow(i)
plt.savefig('./result.png')
# plt.show()
if __name__ == '__main__':
root = './data/COVID/images'
images_path = [os.path.join(root, i) for i in os.listdir(root)]
r = random.randint(0, len(images_path) - 1)
img_path = images_path[r] # 随机取出一张图片
mask_path = img_path.replace('images', 'masks')
# opacity 越小,掩膜效果越深
main(imagePath=img_path, labelPath=mask_path, bgr=(0, 0, 255), opacity=0.5)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
深度学习数据集:COVID-19 胸部 X 光图像和肺部图像分割数据集 (2000个子文件)
COVID-1530.png 2KB
COVID-381.png 2KB
COVID-1503.png 2KB
COVID-1321.png 2KB
COVID-538.png 2KB
COVID-457.png 2KB
COVID-981.png 2KB
COVID-253.png 2KB
COVID-385.png 2KB
COVID-270.png 2KB
COVID-1602.png 2KB
COVID-543.png 2KB
COVID-619.png 2KB
COVID-1020.png 2KB
COVID-717.png 2KB
COVID-461.png 2KB
COVID-1575.png 2KB
COVID-1291.png 2KB
COVID-533.png 2KB
COVID-1563.png 2KB
COVID-389.png 2KB
COVID-569.png 2KB
COVID-247.png 2KB
COVID-132.png 2KB
COVID-1288.png 2KB
COVID-250.png 2KB
COVID-1323.png 2KB
COVID-455.png 2KB
COVID-1614.png 2KB
COVID-1368.png 2KB
COVID-582.png 2KB
COVID-1186.png 2KB
COVID-1023.png 2KB
COVID-1682.png 2KB
COVID-567.png 2KB
COVID-11.png 2KB
COVID-347.png 2KB
COVID-773.png 2KB
COVID-961.png 2KB
COVID-1432.png 2KB
COVID-1002.png 2KB
COVID-1580.png 2KB
COVID-609.png 2KB
COVID-87.png 2KB
COVID-160.png 2KB
COVID-1497.png 2KB
COVID-1100.png 2KB
COVID-1596.png 2KB
COVID-495.png 2KB
COVID-1317.png 2KB
COVID-1417.png 2KB
COVID-996.png 2KB
COVID-135.png 2KB
COVID-1124.png 2KB
COVID-151.png 2KB
COVID-1469.png 2KB
COVID-1506.png 2KB
COVID-1069.png 2KB
COVID-1189.png 2KB
COVID-595.png 2KB
COVID-370.png 2KB
COVID-1072.png 2KB
COVID-423.png 2KB
COVID-1686.png 2KB
COVID-2221.png 2KB
COVID-1273.png 2KB
COVID-1144.png 2KB
COVID-1684.png 2KB
COVID-54.png 2KB
COVID-1093.png 2KB
COVID-1833.png 2KB
COVID-1569.png 2KB
COVID-1542.png 2KB
COVID-600.png 2KB
COVID-297.png 2KB
COVID-2723.png 2KB
COVID-738.png 2KB
COVID-172.png 2KB
COVID-846.png 2KB
COVID-1473.png 2KB
COVID-2182.png 2KB
COVID-1817.png 2KB
COVID-1553.png 2KB
COVID-509.png 2KB
COVID-1326.png 2KB
COVID-1279.png 2KB
COVID-144.png 2KB
COVID-1535.png 2KB
COVID-943.png 2KB
COVID-1827.png 2KB
COVID-666.png 2KB
COVID-1360.png 2KB
COVID-1622.png 2KB
COVID-1648.png 2KB
COVID-1423.png 2KB
COVID-60.png 2KB
COVID-1111.png 2KB
COVID-722.png 2KB
COVID-1706.png 2KB
COVID-2689.png 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Ai医学图像分割
- 粉丝: 2w+
- 资源: 2128
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功