firelab-general/ratio_pyrometry.py

73 lines
1.6 KiB
Python
Raw Normal View History

2022-10-06 00:13:40 -07:00
import math
import cv2 as cv
import numpy as np
from numba import jit
# camera settings
2022-10-06 16:30:55 -07:00
I_Darkcurrent = 150.5
exposure_time = 0.5
f_stop = 2.4
ISO = 64 # basically brightness
# I_Darkcurrent = 50.1
# exposure_time = 0.1
# f_stop = 1
# ISO = 70 # basically brightness
2022-10-06 00:13:40 -07:00
@jit(nopython=True)
def rg_ratio_normalize(imgarr):
imgnew = imgarr
for i in range(len(imgarr)):
for j in range(len(imgarr[i])):
px = imgarr[i][j]
r_norm = normalization_func(px[0])
g_norm = normalization_func(px[1])
# apply camera calibration func
ratio = pyrometry_calibration_formula(g_norm, r_norm)
# remove edge cases
2022-10-06 16:30:55 -07:00
if ratio > 1900:
2022-10-06 00:13:40 -07:00
ratio = 0
imgnew[i][j] = [ratio, ratio, ratio]
return imgnew
@jit(nopython=True)
def normalization_func(i):
return (i - I_Darkcurrent) * (f_stop ** 2) / (ISO * exposure_time)
@jit(nopython=True)
def pyrometry_calibration_formula(i_ng, i_nr):
return 362.73 * math.log10(
(i_ng/i_nr) ** 3
) + 2186.7 * math.log10(
(i_ng/i_nr) ** 3
) + 4466.5 * math.log10(
(i_ng / i_nr) ** 3
) + 3753.5
2022-10-06 16:30:55 -07:00
# read image & crop
2022-10-06 00:13:40 -07:00
img = cv.imread('01-0001.png')
2022-10-06 16:30:55 -07:00
img = img[400:, 420:1200]
# img = cv.imread('ember_test.png')
2022-10-06 00:13:40 -07:00
img = rg_ratio_normalize(img)
2022-10-06 16:30:55 -07:00
# apply smoothing conv kernel
2022-10-06 00:13:40 -07:00
kernel = np.array([
2022-10-06 16:30:55 -07:00
[1/2, 1/2],
[1/2, 1/2],
2022-10-06 00:13:40 -07:00
])
2022-10-06 16:30:55 -07:00
# Scaling adjustment factor
kernel *= 3/5
2022-10-06 00:13:40 -07:00
img = cv.filter2D(src=img, ddepth=-1, kernel=kernel)
2022-10-06 16:30:55 -07:00
# apply jet color map
2022-10-06 00:13:40 -07:00
img = cv.applyColorMap(img, cv.COLORMAP_JET)
2022-10-06 16:30:55 -07:00
2022-10-06 00:13:40 -07:00
cv.imwrite('01-0001-transformed-ratio.png', img)