Python 在灰度图上采样像素点(从图像中心点每隔10°发射一条射线,射线上采样10个点),将结果保存到Excel

代码如下:

import os
import cv2
import math
from math import sqrt
import numpy
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import xlwt
import xlrd
import openpyxl
from PIL import Image
import matplotlib.image as mpimg

workbook = openpyxl.Workbook()
sheet = workbook.active

t = 0  #行

#图片文件夹路径
folder_path = 'C:/Tianyu/AAV/cut_imgs_partial'

for filename in os.listdir(folder_path):

    # 读每张图像
    img = cv2.imread(f'C:/Tianyu/AAV/cut_imgs/{filename}', 0)
    img_1 = cv2.resize(img, (76,76))
    h = img_1.shape[0]
    w = img_1.shape[1]

    x0 = round(w / 2)
    y0 = round(h / 2)

    if w > h:
        R = math.floor(h / 2) - 1
    else:
        R = math.floor(w / 2) - 1

    a = 36 #分成几等分
    t = t + 1
    s = 1
    #每张图片上10个圆
    for i in range(0,10):
        e = R-round(i*R/10)  #等分圆的半径
        #每个圆36等分
        for n in range(1,a+1):
            xx = math.floor(e*np.cos(2*np.pi*(n-1)/a)) + x0 # 坐标
            yy = math.floor(e*np.sin(2*np.pi*(n-1)/a)) + y0

            #打印灰度值
            # print(img_1[xx][yy])
            #列数
            s = s + 1
            sheet.cell(row=t, column = s, value = img_1[xx][yy])
    #打印文件名
    print(f"{filename}")
    sheet.cell(row=t, column = 1, value = f'{filename}')

#Excel保存路径
workbook.save('C:/Tianyu/AAV/内切圆统计/内切圆-partial/内切圆(36×10采样)-Partial.xlsx')

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值