From a3ba159781853286ad57a2caa20fbd8c559aef18 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 4 Jun 2024 08:41:38 -0700 Subject: [PATCH] Add comparison scripts for exposure fusion --- .../compare_bright_lPyramid.py | 73 +++++++++++++++ .../compare_bright_weight_gPyramid.py | 73 +++++++++++++++ .../compare_dark_lPyramid.py | 73 +++++++++++++++ .../compare_dark_weight_gPyramid.py | 73 +++++++++++++++ .../compare_exposure_fusion_output.py | 90 +++++++++++++++++++ .../compare_merged_pyramid.py | 74 +++++++++++++++ .../compare_reconstructed_image.py | 71 +++++++++++++++ .../compare_weight_bright_norm.py | 63 +++++++++++++ .../compare_weight_dark_norm.py | 63 +++++++++++++ 9 files changed, 653 insertions(+) create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_lPyramid.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_weight_gPyramid.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_lPyramid.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_weight_gPyramid.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_exposure_fusion_output.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_merged_pyramid.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_reconstructed_image.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_bright_norm.py create mode 100644 apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_dark_norm.py diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_lPyramid.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_lPyramid.py new file mode 100644 index 000000000..cc0b2ed82 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_lPyramid.py @@ -0,0 +1,73 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + +pyramid_width_list = [1264, 632, 316, 158] +pyramid_height_list = [1136, 568, 284, 142] + +pyramid_level = 3 + +pyramid_width = pyramid_width_list[pyramid_level] +pyramid_height = pyramid_height_list[pyramid_level] + +kayvon_pyramid = np.zeros((pyramid_height, pyramid_width)) + + + +# First load Kayvon's weight pyramid +k_bright_lPyramid_filepath = f"/aha/cs348v_camera_asst/bright_lPyramid_level_{pyramid_level}.txt" + + +k_bright_lPyramid_file = open(k_bright_lPyramid_filepath, 'r') +line = k_bright_lPyramid_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_pyramid[y][x] = float(row[x]) + + line = k_bright_lPyramid_file.readline() + y += 1 + +k_bright_lPyramid_file.close() + + +# print(kayvon_pyramid[0][1][0]) +# print(kayvon_pyramid[0][1][1]) +# print(kayvon_pyramid[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + my_weight_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + abs_difference = abs(my_weight_value - kayvon_pyramid[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_pyramid[y][x]} but got {my_weight_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_weight_gPyramid.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_weight_gPyramid.py new file mode 100644 index 000000000..909ba5742 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_bright_weight_gPyramid.py @@ -0,0 +1,73 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + +pyramid_width_list = [1264, 632, 316, 158] +pyramid_height_list = [1136, 568, 284, 142] + +pyramid_level = 0 + +pyramid_width = pyramid_width_list[pyramid_level] +pyramid_height = pyramid_height_list[pyramid_level] + +kayvon_pyramid = np.zeros((pyramid_height, pyramid_width)) + + + +# First load Kayvon's weight pyramid +k_bright_weight_gPyramid_filepath = f"/aha/cs348v_camera_asst/bright_weight_gPyrmaid_level_{pyramid_level}.txt" + + +k_bright_weight_gPyramid_file = open(k_bright_weight_gPyramid_filepath, 'r') +line = k_bright_weight_gPyramid_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_pyramid[y][x] = float(row[x]) + + line = k_bright_weight_gPyramid_file.readline() + y += 1 + +k_bright_weight_gPyramid_file.close() + + +# print(kayvon_pyramid[0][1][0]) +# print(kayvon_pyramid[0][1][1]) +# print(kayvon_pyramid[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + my_weight_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + abs_difference = abs(my_weight_value - kayvon_pyramid[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_pyramid[y][x]} but got {my_weight_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_lPyramid.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_lPyramid.py new file mode 100644 index 000000000..dc656ef92 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_lPyramid.py @@ -0,0 +1,73 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + +pyramid_width_list = [1264, 632, 316, 158] +pyramid_height_list = [1136, 568, 284, 142] + +pyramid_level = 0 + +pyramid_width = pyramid_width_list[pyramid_level] +pyramid_height = pyramid_height_list[pyramid_level] + +kayvon_pyramid = np.zeros((pyramid_height, pyramid_width)) + + + +# First load Kayvon's weight pyramid +k_dark_lPyramid_filepath = f"/aha/cs348v_camera_asst/dark_lPyramid_level_{pyramid_level}.txt" + + +k_dark_lPyramid_file = open(k_dark_lPyramid_filepath, 'r') +line = k_dark_lPyramid_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_pyramid[y][x] = float(row[x]) + + line = k_dark_lPyramid_file.readline() + y += 1 + +k_dark_lPyramid_file.close() + + +# print(kayvon_pyramid[0][1][0]) +# print(kayvon_pyramid[0][1][1]) +# print(kayvon_pyramid[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + my_weight_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + abs_difference = abs(my_weight_value - kayvon_pyramid[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_pyramid[y][x]} but got {my_weight_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_weight_gPyramid.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_weight_gPyramid.py new file mode 100644 index 000000000..3fd45d4d0 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_dark_weight_gPyramid.py @@ -0,0 +1,73 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + +pyramid_width_list = [1264, 632, 316, 158] +pyramid_height_list = [1136, 568, 284, 142] + +pyramid_level = 0 + +pyramid_width = pyramid_width_list[pyramid_level] +pyramid_height = pyramid_height_list[pyramid_level] + +kayvon_pyramid = np.zeros((pyramid_height, pyramid_width)) + + + +# First load Kayvon's weight pyramid +k_dark_weight_gPyramid_filepath = f"/aha/cs348v_camera_asst/dark_weight_gPyrmaid_level_{pyramid_level}.txt" + + +k_dark_weight_gPyramid_file = open(k_dark_weight_gPyramid_filepath, 'r') +line = k_dark_weight_gPyramid_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_pyramid[y][x] = float(row[x]) + + line = k_dark_weight_gPyramid_file.readline() + y += 1 + +k_dark_weight_gPyramid_file.close() + + +# print(kayvon_pyramid[0][1][0]) +# print(kayvon_pyramid[0][1][1]) +# print(kayvon_pyramid[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + my_weight_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + abs_difference = abs(my_weight_value - kayvon_pyramid[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_pyramid[y][x]} but got {my_weight_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_exposure_fusion_output.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_exposure_fusion_output.py new file mode 100644 index 000000000..6999b1f36 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_exposure_fusion_output.py @@ -0,0 +1,90 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + + +im_width = 1250 +im_height = 1120 +num_color_channels = 3 + +kayvon_image = np.zeros((im_height, im_width, num_color_channels)) + + + +# First load Kayvon's exposure fusion output +k_EF_red_filepath = f"/aha/cs348v_camera_asst/post_exposure_fusion_red_out.txt" +k_EF_green_filepath = f"/aha/cs348v_camera_asst/post_exposure_fusion_green_out.txt" +k_EF_blue_filepath = f"/aha/cs348v_camera_asst/post_exposure_fusion_blue_out.txt" + + +k_EF_red_file = open(k_EF_red_filepath, 'r') +k_EF_green_file = open(k_EF_green_filepath, 'r') +k_EF_blue_file = open(k_EF_blue_filepath, 'r') + +red_line = k_EF_red_file.readline() +green_line = k_EF_green_file.readline() +blue_line = k_EF_blue_file.readline() + +y = 0 +while(red_line): + red_line = red_line.strip() + red_row = red_line.split(', ') + + green_line = green_line.strip() + green_row = green_line.split(', ') + + blue_line = blue_line.strip() + blue_row = blue_line.split(', ') + + for x in range(len(red_row)): + kayvon_image[y][x][0] = red_row[x] + kayvon_image[y][x][1] = green_row[x] + kayvon_image[y][x][2] = blue_row[x] + + red_line = k_EF_red_file.readline() + green_line = k_EF_green_file.readline() + blue_line = k_EF_blue_file.readline() + y += 1 + +k_EF_red_file.close() +k_EF_green_file.close() +k_EF_blue_file.close() + + +# print(kayvon_image[0][1][0]) +# print(kayvon_image[0][1][1]) +# print(kayvon_image[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + pixel_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + c = int(indices[2]) + + abs_difference = abs(pixel_value - kayvon_image[y][x][c]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, c = {c} expected {kayvon_image[y][x][c]} but got {pixel_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_merged_pyramid.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_merged_pyramid.py new file mode 100644 index 000000000..259a7f563 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_merged_pyramid.py @@ -0,0 +1,74 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + +pyramid_width_list = [1264, 632, 316, 158] +pyramid_height_list = [1136, 568, 284, 142] + +pyramid_level = 0 + +pyramid_width = pyramid_width_list[pyramid_level] +pyramid_height = pyramid_height_list[pyramid_level] + +kayvon_pyramid = np.zeros((pyramid_height, pyramid_width)) + + + +# First load Kayvon's weight pyramid +k_merged_pyramid_filepath = f"/aha/cs348v_camera_asst/merged_pyramid_level_{pyramid_level}.txt" + + +k_merged_pyramid_file = open(k_merged_pyramid_filepath, 'r') +line = k_merged_pyramid_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_pyramid[y][x] = float(row[x]) + + line = k_merged_pyramid_file.readline() + y += 1 + +k_merged_pyramid_file.close() + + +# print(kayvon_pyramid[0][1][0]) +# print(kayvon_pyramid[0][1][1]) +# print(kayvon_pyramid[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + my_merged_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + abs_difference = abs(my_merged_value - kayvon_pyramid[y][x]) + + #print("comparing...") + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_pyramid[y][x]} but got {my_merged_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_reconstructed_image.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_reconstructed_image.py new file mode 100644 index 000000000..cb6431c3a --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_reconstructed_image.py @@ -0,0 +1,71 @@ +import numpy as np +import pandas as pd + +trace_file_path = "./out.txt" + + + +reconstructed_image_width = 1264 +reconstructed_image_height = 1136 + +kayvon_reconstructed_image = np.zeros((reconstructed_image_height, reconstructed_image_width)) + + + +# First load Kayvon's reconstructed reconstructed_image +k_reconstructed_image_filepath = f"/aha/cs348v_camera_asst/reconstructed.txt" + + +k_reconstructed_image_file = open(k_reconstructed_image_filepath, 'r') +line = k_reconstructed_image_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_reconstructed_image[y][x] = float(row[x]) + + line = k_reconstructed_image_file.readline() + y += 1 + +k_reconstructed_image_file.close() + + +# print(kayvon_reconstructed_image[0][1][0]) +# print(kayvon_reconstructed_image[0][1][1]) +# print(kayvon_reconstructed_image[0][1][2]) + + + + +# Now, compare to my exposure fusion output +tolerance = 0.001 + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + my_reconstructed_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + print("Comparing...") + abs_difference = abs(my_reconstructed_value - kayvon_reconstructed_image[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_reconstructed_image[y][x]} but got {my_reconstructed_value}. Difference is {abs_difference}.") + + line = trace_file.readline() + +trace_file.close() +#print(my_pixels) + + diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_bright_norm.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_bright_norm.py new file mode 100644 index 000000000..1ce41fe72 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_bright_norm.py @@ -0,0 +1,63 @@ +import numpy as np +import pandas as pd + + + + + +trace_file_path = "./out.txt" + + +im_width = 1264 +im_height = 1136 + + +my_weight_brights = np.zeros((im_height, im_width)) + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + weight_bright_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + + my_weight_brights[y][x] = weight_bright_value + + line = trace_file.readline() + +trace_file.close() +#print(my_weight_brights) + + +# Now, compare to Kayvon's norm_bright_weight output +tolerance = 0.001 +k_norm_bright_weight_filepath = f"/aha/cs348v_camera_asst/norm_bright_weight_out.txt" + + +k_norm_bright_weight_file= open(k_norm_bright_weight_filepath, 'r') +line = k_norm_bright_weight_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_weight_bright_value = float(row[x]) + + abs_difference = abs(kayvon_weight_bright_value - my_weight_brights[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_weight_bright_value} but got {my_weight_brights[y][x]}. Difference is {abs_difference}.") + + line = k_norm_bright_weight_file.readline() + y += 1 +k_norm_bright_weight_file.close() \ No newline at end of file diff --git a/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_dark_norm.py b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_dark_norm.py new file mode 100644 index 000000000..38583bcd5 --- /dev/null +++ b/apps/hardware_benchmarks/apps/exposure_fusion_hdr_plus/compare_weight_dark_norm.py @@ -0,0 +1,63 @@ +import numpy as np +import pandas as pd + + + + + +trace_file_path = "./out.txt" + + +im_width = 1264 +im_height = 1136 + + +my_weight_darks = np.zeros((im_height, im_width)) + +trace_file = open(trace_file_path, "r") + +line = trace_file.readline() +while(line): + if 'Store' in line: + line = line.strip() + components = line.split(' = ') + + indices = components[0].split('(')[1].strip(')').split(', ') + weight_dark_value = float(components[1]) + + x = int(indices[0]) + y = int(indices[1]) + + + my_weight_darks[y][x] = weight_dark_value + + line = trace_file.readline() + +trace_file.close() +#print(my_weight_darks) + + +# Now, compare to Kayvon's norm_dark_weight output +tolerance = 0.001 +k_norm_dark_weight_filepath = f"/aha/cs348v_camera_asst/norm_dark_weight_out.txt" + + +k_norm_dark_weight_file= open(k_norm_dark_weight_filepath, 'r') +line = k_norm_dark_weight_file.readline() + +y = 0 +while(line): + line = line.strip() + row = line.split(', ') + + for x in range(len(row)): + kayvon_weight_dark_value = float(row[x]) + + abs_difference = abs(kayvon_weight_dark_value - my_weight_darks[y][x]) + + if (abs_difference > tolerance): + print(f"At x = {x}, y = {y}, expected {kayvon_weight_dark_value} but got {my_weight_darks[y][x]}. Difference is {abs_difference}.") + + line = k_norm_dark_weight_file.readline() + y += 1 +k_norm_dark_weight_file.close() \ No newline at end of file