diff --git a/.gitignore b/.gitignore index 36f119f..49ac250 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,6 @@ .vscode/ *.swp -static/* -!static/.gitkeep # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/flask_frontend.py b/flask_frontend.py index 706164c..a7aa269 100644 --- a/flask_frontend.py +++ b/flask_frontend.py @@ -6,7 +6,7 @@ import cv2 as cv app = Flask( __name__, - static_folder='./static', + static_folder='static', static_url_path='/s/' ) @@ -27,7 +27,8 @@ def ratio_pyro(): MAX_TEMP=float(request.form['max_temp']), MIN_TEMP=float(request.form['min_temp']), smoothing_radius=int(request.form['smoothing_radius']), - key_entries=int(request.form['legend_entries']) + key_entries=int(request.form['legend_entries']), + eqn_scaling_factor=float(request.form['equation_scaling_factor']) ) img_orig_b64 = base64.b64encode(cv.imencode('.png', img_orig)[1]).decode(encoding='utf-8') diff --git a/ratio_pyrometry.py b/ratio_pyrometry.py index ab71836..b36311b 100644 --- a/ratio_pyrometry.py +++ b/ratio_pyrometry.py @@ -12,7 +12,8 @@ def rg_ratio_normalize( exposure_time, ISO, MIN_TEMP, - MAX_TEMP + MAX_TEMP, + eqn_scaling_factor ): # copy image into new array & chop off alpha values (if applicable) imgnew = imgarr.copy()[:,:,:3] @@ -26,18 +27,14 @@ def rg_ratio_normalize( r_norm = (px[2] - I_Darkcurrent) * (f_stop ** 2) / (ISO * exposure_time) # apply camera calibration func - temp_C = pyrometry_calibration_formula(g_norm, r_norm, default=MIN_TEMP) + temp_C = pyrometry_calibration_formula(g_norm, r_norm, default=MIN_TEMP) * eqn_scaling_factor # remove pixels outside calibration range if (MIN_TEMP != None and temp_C < MIN_TEMP) or (MAX_TEMP != None and temp_C > MAX_TEMP): temp_C = MIN_TEMP - # min intensity = 0 - # pix_i = temp_C - MIN_TEMP - - temp_new = temp_C - MIN_TEMP - pix_i = temp_new / (MAX_TEMP - MIN_TEMP) * 255 - + # scale light intensity to calculated temperature + pix_i = scale_temp(temp_C, MIN_TEMP, MAX_TEMP) imgnew[i][j] = [pix_i, pix_i, pix_i] return imgnew @@ -59,6 +56,15 @@ def pyrometry_calibration_formula(i_ng, i_nr, default=24.0): except: return default + +@jit(nopython=True) +def scale_temp(t, min, max): + """ + Scale pixel temperature (t) to light intensity given min & max temp. + """ + return (t - min) / (max - min) * 255 + + def ratio_pyrometry_pipeline( file_bytes, # camera settings @@ -70,12 +76,12 @@ def ratio_pyrometry_pipeline( MAX_TEMP: float, MIN_TEMP: float, smoothing_radius: int, - key_entries: int + key_entries: int, + eqn_scaling_factor: float, ): # read image & crop img_orig = cv.imdecode(file_bytes, cv.IMREAD_UNCHANGED) - # img = img[y1:y2, x1:x2] img = rg_ratio_normalize( img_orig, @@ -84,7 +90,8 @@ def ratio_pyrometry_pipeline( exposure_time, ISO, MIN_TEMP, - MAX_TEMP + MAX_TEMP, + eqn_scaling_factor ) # build & apply smoothing conv kernel @@ -107,7 +114,7 @@ def ratio_pyrometry_pipeline( key_img_arr = [[]] for i in range(key_entries): res_temp = MIN_TEMP + (i * step) - res_color = (res_temp - MIN_TEMP) / (MAX_TEMP - MIN_TEMP) * 255 + res_color = scale_temp(res_temp, MIN_TEMP, MAX_TEMP) temps.append(math.floor(res_temp)) key_img_arr[0].append([res_color, res_color, res_color]) diff --git a/static/.gitkeep b/static/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/static/pyrometry_eqn.png b/static/pyrometry_eqn.png new file mode 100644 index 0000000..fe2c725 Binary files /dev/null and b/static/pyrometry_eqn.png differ diff --git a/templates/index.jinja2 b/templates/index.jinja2 index 34c7f69..3dad235 100644 --- a/templates/index.jinja2 +++ b/templates/index.jinja2 @@ -29,13 +29,21 @@