Skip to content

Commit ab9856f

Browse files
committed
Add comparison to ref img in tb
1 parent 514af9c commit ab9856f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

modules/unification/unification_tb.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ int sc_main (int argc, char* argv[]) {
2020
int i;
2121
int width, height, channels, pixel_count;
2222
unsigned char *img_x, *img_y, *img_unificated;
23+
24+
//Ref Image pointer
25+
unsigned char *img_ref;
26+
int error_count;
27+
float error_med;
2328

2429
unification_module unification_U1 ("unification_U1");
2530

@@ -35,6 +40,7 @@ int sc_main (int argc, char* argv[]) {
3540
// Load Image
3641
img_x = stbi_load("../../tools/datagen/src/imgs/car_sobel_x_result.jpg", &width, &height, &channels, 0);
3742
img_y = stbi_load("../../tools/datagen/src/imgs/car_sobel_y_result.jpg", &width, &height, &channels, 0);
43+
img_ref = stbi_load("../../tools/datagen/src/imgs/car_sobel_combined_result.jpg", &width, &height, &channels, 0);
3844
pixel_count = width * height * channels;
3945

4046
//Allocate memory for output image
@@ -54,7 +60,23 @@ int sc_main (int argc, char* argv[]) {
5460
//Iterate over image
5561
unification_U1.unificate_img(img_x, img_y, img_unificated, pixel_count, channels);
5662
printf("Unification finished.\n");
57-
//FIXME: Add comparison with reference combined image, and time measurement
63+
64+
//Compare with reference image
65+
error_count = 0;
66+
error_med = 0;
67+
for(unsigned char *ref = img_ref, *result = img_unificated; ref < img_ref + pixel_count && result< img_unificated + pixel_count; ref+=channels, result+=channels){
68+
//printf("Pixel #%0d, Ref Value: %0d, Result Value: %0d\n", int(ref-img_ref), *ref, *result);
69+
error_count += (*ref != *result);
70+
error_med += abs(*ref - *result);
71+
}
72+
error_med /= error_count;
73+
printf("-----------------------------------\n");
74+
printf("Comparison Results:\n");
75+
printf("Error Count: %0d, Error Rate: %0.2f\n", error_count, (100*(error_count+0.0))/pixel_count);
76+
printf("Mean Error Distance: %0.2f\n", error_med);
77+
printf("-----------------------------------\n");
78+
79+
//FIXME: Add time measurement
5880

5981
cout << "@" << sc_time_stamp() <<" Terminating simulation\n" << endl;
6082

0 commit comments

Comments
 (0)