Skip to content

Commit 18ad765

Browse files
committed
Add error estimation to tb
1 parent d205e4e commit 18ad765

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

HLS/IpsFilterHLS/src/tb_module.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#define IPS_FILTER_KERNEL_SIZE 3
1515
#define DELAY_TIME (IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE * 1) + 4 + 2 + 1
16-
#define IPS_IMG_PATH_TB "../../../inputs/car_noisy_image.jpg"
16+
#define IPS_IMG_PATH_TB "../../../inputs/car_noisy_image.png"
1717

1818
SC_MODULE (testbench) {
1919
sc_out<sc_uint<8> > img_window[IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE];
@@ -109,6 +109,11 @@ SC_MODULE (testbench) {
109109
cv::Mat image;
110110
read_image.convertTo(image, CV_8U);
111111

112+
//For error calculation
113+
sc_uint<16> mean_result;
114+
sc_uint<8> error;
115+
sc_uint<16> mean_error;
116+
112117
cv::Mat o_img(image.size(), image.type());
113118

114119
// Check if the image is loaded successfully
@@ -124,12 +129,11 @@ SC_MODULE (testbench) {
124129
std::cout << " cols = " << image.cols;
125130
std::cout << " channels = " << image.channels() << std::endl;
126131
}
127-
128-
// image.rows = 100;
129-
// image.cols = 100;
130132
sc_uint<8> local_window[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
131133
sc_uint<8> result;
132134

135+
mean_error = 0;
136+
133137
// Create each windown and filter
134138
for (int y = 0; y < image.rows - IPS_FILTER_KERNEL_SIZE; ++y)
135139
{
@@ -142,26 +146,31 @@ SC_MODULE (testbench) {
142146
// Define the Window
143147
extract_window(y, x, image, &local_window[0], image.cols, image.rows);
144148

149+
mean_result = 0;
150+
145151
for (int i = 0; i < IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE; ++i)
146152
{
147153
//local_window[i* IPS_FILTER_KERNEL_SIZE + j] = sub_img.data[i* IPS_FILTER_KERNEL_SIZE + j];
148154
img_window[i].write(local_window[i]);
155+
mean_result += local_window[i];
149156
#ifdef IPS_DEBUG_EN
150157
std::cout << "[" << (int) local_window[i] << "]";
151158
#endif // IPS_DEBUG_EN
152159
}
153160
#ifdef IPS_DEBUG_EN
154161
std::cout << std::endl;
155162
#endif // IPS_DEBUG_EN
163+
mean_result /= (IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE);
164+
156165
wait(DELAY_TIME + 10, SC_NS);
157166
result = mean.read();
158-
// cout << "Read Result: " << (int) result << endl;
159-
// result = (sc_uint<8>) local_window[0];
160167
o_img.data[y*image.cols + x]= result;
161168
//*o_img.ptr(y, x) = result;
169+
error = abs(mean_result - result);
170+
mean_error += error;
162171
#ifdef IPS_DEBUG_EN
163172
// SC_REPORT_INFO("TEST_MODE_IMAGE", "filtering");
164-
std::cout << "Iteration: " << (int) y*image.cols + x << " Original Pixel: " << (int) image.data[y* image.rows + x] << " Result = " << (int) result << std::endl;
173+
// std::cout << "Iteration: " << (int) y*image.cols + x << " Result = " << (int) result << " Expected result = " << (int) mean_result << " Error: " << (int) error << std::endl;
165174
#endif // IPS_DEBUG_E
166175
}
167176
}
@@ -172,6 +181,8 @@ SC_MODULE (testbench) {
172181
// Save the final image
173182
std::string output_img_path = "filtered_image.png";
174183
cv::imwrite(output_img_path, final_img);
184+
std::cout << "Test finished with Mean error: " << ((float) mean_error)/(image.rows*image.cols) << " Total error: "<< mean_error << std::endl;
185+
175186
}
176187
#endif //TEST_MODE_IMAGE
177188

0 commit comments

Comments
 (0)