python 图像分割
来源:互联网 发布:java des加密算法 编辑:程序博客网 时间:2024/06/07 00:00
`分割标签转换import cv2import oscolorMap = [[0,0,0],[128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128],[128,128,128],[64,0,0],[192,0,0],[64,128,0],[192,128,0],[64,0,128],[192,0,128],[64,128,128],[192,128,128],[0,64,0],[128,64,0],[0,192,0],[128,192,0],[0,64,128],[128,128,128]] #RGBdef cvtColorToIndex(colorImage): global colorMap outImage = colorImage.copy() outImage[...] = 0 for i in range(len(colorMap)): idx1 = colorImage[:, :, 0] == colorMap[i][2] idx2 = colorImage[:, :, 1] == colorMap[i][1] idx3 = colorImage[:, :, 2] == colorMap[i][0] idx = idx1 * idx2 * idx3 outImage[idx,:] = i return outImagedef processDir(srcdir, dstdir): fs = os.listdir(srcdir) if not os.path.exists(dstdir): os.makedirs(dstdir) for i in range(len(fs)): newImage = cvtColorToIndex(cv2.imread(srcdir + "/" + fs[i])) cv2.imwrite(dstdir + "/" + fs[i], newImage) print "process [%d] %s" % (i, fs[i])processDir("SegmentationClass", "1")`
`输出像素from PIL import Imageimg=Image.open("2007_000032.png")img_array=img.load()size=img.sizeprint img.modeprint size[1]for i in range(size[0]): for j in range(size[1]): if (img_array[i,j]!=[0]): print img_array[i,j]
path 图2 txt
import osdef ListFilesToTxt(dir,file,wildcard,recursion): exts = wildcard.split(" ") for root, subdirs, files in os.walk(dir): for name in files: portion = os.path.splitext(name) for ext in exts: if(name.endswith(ext)): file.write('/home/calmcar/lly/deeplab1/exper/datavoc/SegmentationObject/'+portion[0]+"\n") #file.write(portion[0]+ '.png'+"\n") break if(not recursion): breakdef Test(): dir="/home/calmcar/lly/deeplab1/exper/datavoc/SegmentationObject/" outfile="file.txt" wildcard = ".png" file = open(outfile,"w") if not file: print ("cannot open the file %s for writing" % outfile) ListFilesToTxt(dir,file,wildcard, 0) file.close()Test()
阅读全文
0 0
- python 图像分割
- Kmeans 图像分割 by python
- python libsvm 图像分割 字符识别
- Python计算机视觉:第九章 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- 图像分割
- dubbo调用中数据丢失问题的记录
- powerdesigner 数据类型与数据库数据类型对应
- DirectX学习(三)表面
- BigDecimal比较大小
- STM32F207上I2C作为从机的硬件中断实现的代码及注释
- python 图像分割
- win10, net framework 3.5 安装报错0x800F081F的解决方法
- Android 异步消息处理机制
- Intellij Ideay一、开启自动编译
- Gradle 入门到精通(三)
- Python学习(0)
- Android
- centos7 切换文本/图形界面
- sublime 快捷键收藏