利用genjson和WSI切片生成训练集

该代码段主要展示了如何利用genjson中的几何信息和WSI切片来创建图像训练集及其对应的mask。首先,从geojson文件中提取多边形坐标,然后读取图片路径,接着根据图片路径获取坐标信息,最后生成并保存mask图像以及对应的图像信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

利用genjson和WSI切片生成训练集与对应的mask

import cv2
import numpy as np
import json
import os
import glob
from PIL import Image
# 获取图片信息
# 1、利用WSI生成带有坐标信息的片,得到数据文件夹
img = np.zeros((1080, 1920), np.uint8)

# 获取多边形信息,从geojson中获取
def gen_coordinate(path_to_geojson:str)->list : # return :[[id,label,coordinate],[],...]
    with open(path_to_geojson,encoding="utf-8") as f:
        a = json.load(f,encoding="utf-8")
    coordinate=[]
    for i in range(len(a['features'])):
        current = []
        label = 0
        
        if a['features'][0]['properties']['classification']['name'] =='低级别':
            label = 1
            
        current.append(i)
        current.append(label)
        current.append(a['features']<
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值