将图片颜色值写入excel 并使用同样的背景色填充对应单元格背景 对分析图像提供可视化数据信息
,其中单元格数据是像素坐标和像素颜色值,给大家参考一下
import os.path import sys import datetime import cv2 import xlsxwriter from PIL import Image import numpy as np #基本思路 读入一张图片 把像素坐标及像素值写入excel对应单元格 def writeImageFile(imagefileName,excelfileName='test.xlsx'): curentDir = os.getcwd() if os.path.exists(excelfileName): if len(os.path.split(excelfileName)[0])==0: curentDir=os.getcwd() else: curentDir =os.path.split(excelfileName)[0] if not os.path.exists(imagefileName): print("图片不存在!") sys.exit() #判断 是否为图片 如果图片是四通道 转为三通道 if os.path.splitext(imagefileName)[1] in ['.jpg','.jpeg','.bmp','.tif','.tiff','.png','webp']: imgg = Image.open(imagefileName) imgg = imgg.convert("RGB") imgg.save(imagefileName) # imgdata&