以下面图像为例:
实现代码:
import os
import cv2
import math
from math import sqrt
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import matplotlib.image as mpimg
point_list = []
# 读图像
img_1 = cv2.imread(f'图像路径')
h = img_1.shape[0] #图像高度
w = img_1.shape[1] #图像宽度
#图像中心点坐标
x0 = round(w / 2)
y0 = round(h / 2)
#图像内切圆半径
if x0 >= y0:
R = y0 - 2
else:
R = x0 - 2
a = 36 #图像分成36等分,即10°发射一条射线
for i in range(0 ,10): #10代表每条射线上10个采样点
e = R-round(i*R/10) #每隔多远在射线上进行一次采样
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
a1 = img_1[xx][yy]
print(a1) #打印采样点像素值
point_list.append((xx,yy))
#上绘制采样点
for point in point_list:
cv2.circle(img_1, point, 1, (0, 0, 255), 1)
cv2.imshow("image", img_1) # 显示图片
#保存路径,路径不能有中文
save_path = '保存路径'
cv2.imwrite(save_path, img_1)
cv2.waitKey(0) #等待按键
输出结果如下: