more progress on key generation

master
michael 2022-10-10 13:21:00 -05:00
parent d8bb0c7565
commit 37fd33c0f3
5 changed files with 55 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -4,19 +4,27 @@
<th>Temperature</th>
</tr>
<tr>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:red;"></div></td>
<td class="legend-cell">700°C</td>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:rgb(256, 176, 0);"></div></td>
<td class="legend-cell">0°C</td>
</tr>
<tr>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:red;"></div></td>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:rgb(168, 0, 0);"></div></td>
<td class="legend-cell">800°C</td>
</tr>
<tr>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:red;"></div></td>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:rgb(0, 96, 255);"></div></td>
<td class="legend-cell">900°C</td>
</tr>
<tr>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:red;"></div></td>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:rgb(106, 255, 150);"></div></td>
<td class="legend-cell">1000°C</td>
</tr>
<tr>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:rgb(255, 136, 0);"></div></td>
<td class="legend-cell">1000°C</td>
</tr>
<tr>
<td class="legend-cell"><div style="width:20px;height:20px;background-color:rgb(128, 0, 0);"></div></td>
<td class="legend-cell">1000°C</td>
</tr>
</table>

View File

@ -12,8 +12,8 @@ f_stop = 2.4
ISO = 64 # basically brightness
# pyrometry config
MAX_GR_RATIO = 1200
MIN_GR_RATIO = 0
MAX_TEMP = 1200
MIN_TEMP = 60
# original range from paper
# MAX_GR_RATIO = 1200
# MIN_GR_RATIO = 600
@ -27,10 +27,17 @@ y2 = -1
# post-processing
smoothing_radius = 2
# temperature key generation
key_entries = 6
@jit(nopython=True)
def rg_ratio_normalize(imgarr):
tmin = MAX_GR_RATIO
# set max & min to most extreme values,
# work up & down respectively from there
tmin = MAX_TEMP
tmax = 0
imgnew = imgarr
for i in range(len(imgarr)):
for j in range(len(imgarr[i])):
@ -42,7 +49,7 @@ def rg_ratio_normalize(imgarr):
temp_C = pyrometry_calibration_formula(g_norm, r_norm)
# remove pixels outside calibration range
if MAX_GR_RATIO != None and temp_C > MAX_GR_RATIO or MIN_GR_RATIO != None and temp_C < MIN_GR_RATIO:
if MAX_TEMP != None and temp_C > MAX_TEMP or MIN_TEMP != None and temp_C < MIN_TEMP:
temp_C = 0
# update min & max
@ -96,12 +103,39 @@ print(f"max: {tmax}°C")
k = []
for i in range(smoothing_radius):
k.append([1/(smoothing_radius**2) for i in range(smoothing_radius)])
# for j in range(smoothing_radius):
kernel = np.array(k)
img = cv.filter2D(src=img, ddepth=-1, kernel=kernel)
# apply jet color map
img = cv.applyColorMap(img, cv.COLORMAP_JET)
# write colormapped image
img_jet = cv.applyColorMap(img, cv.COLORMAP_JET)
cv.imwrite(f'{file_name}-cropped-transformed-ratio.{file_ext}', img_jet)
cv.imwrite(f'{file_name}-cropped-transformed-ratio.{file_ext}', img)
# --- Generate temperature key ---
# adjust max & min temps to be the same as the image
# tmin_adj = tmin / (smoothing_radius ** 2)
# tmax_adj = tmax / (smoothing_radius ** 2)
# Generate 6-step key
step = (tmax - tmin) / (key_entries-1)
temps = []
key_img_arr = [[]]
for i in range(key_entries):
res_temp = tmin + (i * step)
res_color = (tmax - (i * step)) / MAX_TEMP * 255
temps.append(res_temp)
key_img_arr[0].append([res_color, res_color, res_color])
key_img = np.array(key_img_arr).astype(np.uint8)
key_img_jet = cv.applyColorMap(key_img, cv.COLORMAP_JET)
# cv.imwrite(f'{file_name}-key.{file_ext}', key_img_jet)
tempkey = {}
for i in range(len(temps)):
c = key_img_jet[0][i]
tempkey[temps[i]] = f"rgb({c[0]}, {c[1]}, {c[2]})"
# with open(f"{file_name}-tempkey.json", "w+") as file_out:
# json.dump(tempkey, file_out)
print(json.dumps(tempkey, indent=4))