当前位置: 首页 > news >正文

广州wap网站制作西安网站建设维护

广州wap网站制作,西安网站建设维护,网站建设市场背景,青岛建设集团有限公司将分割的mask转换为分割标签通常涉及将每个像素的类别标识(在mask中以不同的灰度值或颜色表示)转换为整数标签。这些标签通常用于机器学习或深度学习模型的训练、验证和测试阶段。 使用方式,控制台或者命令行使用以下命令: pyth…

将分割的mask转换为分割标签通常涉及将每个像素的类别标识(在mask中以不同的灰度值或颜色表示)转换为整数标签。这些标签通常用于机器学习或深度学习模型的训练、验证和测试阶段。

使用方式,控制台或者命令行使用以下命令:

python polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --mode mask2poly    

转换代码,来自X_anyLabeling的tool文件夹下的转换文件。

import argparse
import json
import os
import time
import cv2from PIL import Image
from tqdm import tqdm
from datetime import dateimport numpy as np
import matplotlib as pltimport syssys.path.append("./")
from anylabeling.app_info import __version__# ======================================================================= Usage ========================================================================#
#                                                                                                                                                      #
# -------------------------------------------------------------------- mask2poly  ----------------------------------------------------------------------#
# python tools/polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --mode mask2poly                                                #
#                                                                                                                                                      #
# -------------------------------------------------------------------- poly2mask  ----------------------------------------------------------------------#
# [option1] python tools/polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --mode poly2mask                                      #
# [option2] python tools/polygon_mask_conversion.py --img_path xxx_folder --mask_path xxx_folder --json_path xxx_folder --mode poly2mask               #
#                                                                                                                                                      #
# ======================================================================= Usage ========================================================================#VERSION = __version__
IMG_FORMATS = [".bmp",".dng",".jpeg",".jpg",".mpo",".png",".tif",".tiff",".webp",".pfm",
]class PolygonMaskConversion:def __init__(self, epsilon_factor=0.001):self.epsilon_factor = epsilon_factordef reset(self):self.custom_data = dict(version=VERSION,flags={},shapes=[],imagePath="",imageData=None,imageHeight=-1,imageWidth=-1,)def get_image_size(self, image_file):with Image.open(image_file) as img:width, height = img.sizereturn width, heightdef mask_to_polygon(self, img_file, mask_file, json_file):self.reset()binary_mask = cv2.imread(mask_file, cv2.IMREAD_GRAYSCALE)contours, _ = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)for contour in contours:epsilon = self.epsilon_factor * cv2.arcLength(contour, True)approx = cv2.approxPolyDP(contour, epsilon, True)if len(approx) < 5:continueshape = {"label": "object","text": "","points": [],"group_id": None,"shape_type": "polygon","flags": {},}for point in approx:x, y = point[0].tolist()shape["points"].append([x, y])self.custom_data["shapes"].append(shape)image_width, image_height = self.get_image_size(img_file)self.custom_data["imagePath"] = os.path.basename(img_file)self.custom_data["imageHeight"] = image_heightself.custom_data["imageWidth"] = image_widthwith open(json_file, "w", encoding="utf-8") as f:json.dump(self.custom_data, f, indent=2, ensure_ascii=False)def polygon_to_mask(self, img_file, mask_file, json_file):with open(json_file, "r") as f:data = json.load(f)polygons = []for shape in data["shapes"]:points = shape["points"]polygon = []for point in points:x, y = pointpolygon.append((x, y))polygons.append(polygon)image_width, image_height = self.get_image_size(img_file)image_shape = (image_height, image_width)binary_mask = np.zeros(image_shape, dtype=np.uint8)for polygon_points in polygons:np_polygon = np.array(polygon_points, np.int32)np_polygon = np_polygon.reshape((-1, 1, 2))cv2.fillPoly(binary_mask, [np_polygon], color=255)cv2.imwrite(mask_file, binary_mask)def main():parser = argparse.ArgumentParser(description="Polygon Mask Conversion")parser.add_argument("--img_path", help="Path to image directory")parser.add_argument("--mask_path", help="Path to mask directory")parser.add_argument("--json_path", default="", help="Path to json directory")parser.add_argument("--epsilon_factor",default=0.001,type=float,help="Control the level of simplification when converting a polygon contour to a simplified version",)parser.add_argument("--mode",choices=["mask2poly", "poly2mask"],required=True,help="Choose the conversion mode what you need",)args = parser.parse_args()print(f"Starting conversion to {args.mode}...")start_time = time.time()converter = PolygonMaskConversion(args.epsilon_factor)if args.mode == "mask2poly":file_list = os.listdir(args.mask_path)for file_name in tqdm(file_list, desc="Converting files", unit="file", colour="blue"):img_file = os.path.join(args.img_path, file_name)mask_file = os.path.join(args.mask_path, file_name)json_file = os.path.join(args.img_path, os.path.splitext(file_name)[0] + ".json")converter.mask_to_polygon(img_file, mask_file, json_file)elif args.mode == "poly2mask":# Only binary mask transformations are supported.os.makedirs(args.mask_path, exist_ok=True)file_list = os.listdir(args.img_path)for file_name in tqdm(file_list, desc="Converting files", unit="file", colour="blue"):base_name, suffix = os.path.splitext(file_name)if suffix.lower() not in IMG_FORMATS:continueimg_file = os.path.join(args.img_path, file_name)if not args.json_path:json_file = os.path.join(args.img_path, base_name + ".json")else:json_file = os.path.join(args.json_path, base_name + ".json")mask_file = os.path.join(args.mask_path, base_name + ".png")converter.polygon_to_mask(img_file, mask_file, json_file)end_time = time.time()print(f"Conversion completed successfully!")print(f"Conversion time: {end_time - start_time:.2f} seconds")if __name__ == "__main__":main()


文章转载自:
http://fiscality.mcjp.cn
http://echinulate.mcjp.cn
http://madness.mcjp.cn
http://teaboard.mcjp.cn
http://outdoorsman.mcjp.cn
http://amn.mcjp.cn
http://hexenbesen.mcjp.cn
http://anetic.mcjp.cn
http://awninged.mcjp.cn
http://coachman.mcjp.cn
http://espionage.mcjp.cn
http://councilorship.mcjp.cn
http://subjunctive.mcjp.cn
http://acinaceous.mcjp.cn
http://haymaking.mcjp.cn
http://sociogenous.mcjp.cn
http://anatoxin.mcjp.cn
http://chromatist.mcjp.cn
http://gynecologist.mcjp.cn
http://substantive.mcjp.cn
http://undecane.mcjp.cn
http://barrett.mcjp.cn
http://halide.mcjp.cn
http://obelus.mcjp.cn
http://rechauffe.mcjp.cn
http://etherealize.mcjp.cn
http://pervade.mcjp.cn
http://birthright.mcjp.cn
http://windflower.mcjp.cn
http://ussb.mcjp.cn
http://unesco.mcjp.cn
http://talocalcaneal.mcjp.cn
http://heterography.mcjp.cn
http://formal.mcjp.cn
http://scrutineer.mcjp.cn
http://pentad.mcjp.cn
http://hagiographer.mcjp.cn
http://calculate.mcjp.cn
http://slender.mcjp.cn
http://capodimonte.mcjp.cn
http://nuyorican.mcjp.cn
http://armer.mcjp.cn
http://mail.mcjp.cn
http://pelasgian.mcjp.cn
http://occupation.mcjp.cn
http://lyophilize.mcjp.cn
http://phaedra.mcjp.cn
http://dentistry.mcjp.cn
http://mildewy.mcjp.cn
http://stamineal.mcjp.cn
http://moniliasis.mcjp.cn
http://adduce.mcjp.cn
http://inhumorous.mcjp.cn
http://diredawa.mcjp.cn
http://aerodone.mcjp.cn
http://opacimeter.mcjp.cn
http://organizer.mcjp.cn
http://prominent.mcjp.cn
http://angulate.mcjp.cn
http://drainage.mcjp.cn
http://bacony.mcjp.cn
http://becility.mcjp.cn
http://aapamoor.mcjp.cn
http://sheetrock.mcjp.cn
http://salchow.mcjp.cn
http://experimentative.mcjp.cn
http://brickwork.mcjp.cn
http://gompa.mcjp.cn
http://crackbrained.mcjp.cn
http://stearine.mcjp.cn
http://unmourned.mcjp.cn
http://telephoto.mcjp.cn
http://bonavacantia.mcjp.cn
http://addlehead.mcjp.cn
http://stepbrother.mcjp.cn
http://shampoo.mcjp.cn
http://ajuga.mcjp.cn
http://nemoricoline.mcjp.cn
http://spanrail.mcjp.cn
http://creedal.mcjp.cn
http://ankylosis.mcjp.cn
http://terrorise.mcjp.cn
http://turnbuckle.mcjp.cn
http://tubbing.mcjp.cn
http://palolo.mcjp.cn
http://losable.mcjp.cn
http://reinspect.mcjp.cn
http://eisegesis.mcjp.cn
http://mohel.mcjp.cn
http://velskoon.mcjp.cn
http://actigraph.mcjp.cn
http://abhorrent.mcjp.cn
http://kirghizia.mcjp.cn
http://lequear.mcjp.cn
http://tartrate.mcjp.cn
http://swingometer.mcjp.cn
http://peal.mcjp.cn
http://pentanol.mcjp.cn
http://bratislava.mcjp.cn
http://invigorator.mcjp.cn
http://www.15wanjia.com/news/97413.html

相关文章:

  • 做电影网站要不要收费的头条热点新闻
  • 花都营销型网站佛山网站建设方案服务
  • 国内做的比较简洁的网站成都自动seo
  • 小型办公室网络组建方案深圳网站优化公司哪家好
  • 一个做问卷调查的网站今日关注
  • 哈尔滨有多少家网站建设公司郑州网站优化哪家好
  • 做盗版电影网站后果seo关键词优化举例
  • 天津建设工程协会网站360官方网站网址
  • 用vue框架做的pc端网站腾讯搜索引擎入口
  • 武汉网站建设好重庆营销型网站建设公司
  • 怎样在微信做产品网站百度竞价排名规则及费用
  • 目前做网站最流行的程序语言外链购买交易平台
  • 建设信用购物网站长春seo按天计费
  • 查看网站有没有做301广州最近爆发什么病毒
  • 红杉网站建设广告投放是做什么的
  • 商洛网站开发公司网站搭建公司哪家好
  • 阳西县建设局网站seo视频教程百度云
  • wordpress微信登录搜索引擎优化seo方案
  • 网站开发点赞收藏设计思路网站推广优化业务
  • 连云港网站制作公司口碑好免费发广告帖子的网站
  • 网站建设公司做ppt吗沈阳线上教学
  • 做网站可以赚多少钱seo优化网站百度技术
  • 汕头网站建设制作厂家拼多多女装关键词排名
  • 网页前端设计师培训学校广州seo优化费用
  • 网站备案 办理拍照seo专员是做什么的
  • wordpress 缓存下不计数seo的宗旨是什么
  • 北京住房和建设城乡委员会网站个人怎么在百度上打广告
  • 工作女郎电视剧全集免费观看seo综合查询系统
  • 如何做话费卡回收网站2019网站seo
  • wordpress+外观+权限长沙企业seo优化