Python 在图像中心点上每隔一定角度发射一条射线,在射线上进行像素点采样,并打印输出采样点,保存图像

 以下面图像为例:

 

实现代码: 

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) #等待按键

输出结果如下: 

 

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值