用Python进行RU计算
一、说明
Relative Uniformity的计算步骤:
- RAW转Y进行计算
- 按照公式要求进行点位的计算
- 然后按照每个半径下值进行结果的判断
下图只是一个示例,
二、上代码
只上部分代码,请理解,有疑问可以沟通
import cv2
import numpy as np
import img_raw
for seq in range(ringNums):
r = (seq + 1.5) * ringSpacing
numSquares = 8 * (seq + 1)
for m in range(numSquares):
tempAngle = 2 * np.pi * m / numSquares
m_x = np.cos(tempAngle)
m_y = np.sin(tempAngle)
temppts_x = int(nImageWidth / 2 + r * m_x - blockSize // 2)
temppts_y = int(nImageHeight / 2 + r * m_y - blockSize // 2)
if 0 <= temppts_x < nImageWidth - blockSize and 0 <= temppts_y < nImageHeight - blockSize:
block = img[temppts_y:temppts_y + blockSize, temppts_x:temppts_x + blockSize]
rings_blockMeanY[seq].append(np.mean(block))
#= 绘制ROI(如果需要)
cv2.rectangle(rgb_image, (temppts_x, temppts_y), (temppts_x + blockSize, temppts_y + blockSize), (0,0,0), 5)
#将RAW10转换为RAW8,用于画图
raw_data_8bit = (img1 / 4).astype(np.uint8)
rgb_image = cv2.cvtColor(raw_data_8bit, cv2.COLOR_BAYER_BG2RGB)
cv2.namedWindow(‘RU’, cv2.WINDOW_NORMAL)
cv2.imshow(‘RU’, rgb_image)
cv2.waitKey(0)
cv2.destroyAllWindows()