Skip to content

Commit cc77e0d

Browse files
committed
Add first thought of LT model of edge-detector
1 parent e8837e1 commit cc77e0d

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifdef EDGE_DETECTOR_LT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_HPP
3+
#define SOBEL_EDGE_DETECTOR_HPP
4+
5+
#include <systemc.h>
6+
7+
SC_MODULE(Edge_Detector)
8+
{
9+
10+
int localWindow[3][3];
11+
12+
const int sobelGradientX[3][3] = {{-1, 0, 1},
13+
{-2, 0, 2},
14+
{-1, 0, 1}};
15+
const int sobelGradientY[3][3] = {{-1, -2, -1},
16+
{ 0, 0, 0},
17+
{ 1, 2, 1}};
18+
19+
int resultSobelGradientX;
20+
int resultSobelGradientY;
21+
22+
sc_event gotLocalWindow, finishedSobelGradientX, finishedSobelGradientY;
23+
24+
SC_CTOR(Edge_Detector)
25+
{
26+
SC_THREAD(compute_sobel_gradient_x);
27+
SC_THREAD(compute_sobel_gradient_y);
28+
}
29+
30+
void set_local_window(int window[3][3]);
31+
32+
void compute_sobel_gradient_x();
33+
34+
void compute_sobel_gradient_y();
35+
36+
int obtain_sobel_gradient_x();
37+
38+
int obtain_sobel_gradient_y();
39+
40+
};
41+
42+
#endif // SOBEL_EDGE_DETECTOR_HPP
43+
#endif // EDGE_DETECTOR_LT_EN
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#ifdef EDGE_DETECTOR_LT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_CPP
3+
#define SOBEL_EDGE_DETECTOR_CPP
4+
5+
#include "sobel_edge_detector_lt_model.hpp"
6+
7+
void Edge_Detector::set_local_window(int window[3][3])
8+
{
9+
for (int i = 0; i < 3; i++)
10+
{
11+
for (int j = 0; j < 3; j++)
12+
{
13+
this->localWindow[i][j] = window[i][j];
14+
}
15+
}
16+
gotLocalWindow.notify(10, SC_NS);
17+
}
18+
19+
void Edge_Detector::compute_sobel_gradient_x()
20+
{
21+
while (true)
22+
{
23+
wait(gotLocalWindow);
24+
this->resultSobelGradientX = 0;
25+
26+
for (int i = 0; i < 3; i++)
27+
{
28+
for (int j = 0; j < 3; j++)
29+
{
30+
this->resultSobelGradientX += this->localWindow[i][j] * this->sobelGradientX[i][j];
31+
}
32+
}
33+
finishedSobelGradientX.notify(5, SC_NS);
34+
}
35+
}
36+
37+
void Edge_Detector::compute_sobel_gradient_y()
38+
{
39+
while (true)
40+
{
41+
wait(gotLocalWindow);
42+
this->resultSobelGradientY = 0;
43+
44+
for (int i = 0; i < 3; i++)
45+
{
46+
for (int j = 0; j < 3; j++)
47+
{
48+
this->resultSobelGradientY += this->localWindow[i][j] * this->sobelGradientY[i][j];
49+
}
50+
}
51+
finishedSobelGradientY.notify(5, SC_NS);
52+
}
53+
}
54+
55+
int Edge_Detector::obtain_sobel_gradient_x()
56+
{
57+
return this->resultSobelGradientX;
58+
}
59+
60+
int Edge_Detector::obtain_sobel_gradient_y()
61+
{
62+
return this->resultSobelGradientY;
63+
}
64+
65+
#endif // SOBEL_EDGE_DETECTOR_CPP
66+
#endif // EDGE_DETECTOR_LT_EN

modules/edge-detector/src/tb_edge_detector.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ int sc_main(int, char*[])
3131
int** tmpValues;
3232
int maxTmpValue = 0;
3333
#endif // TEST_NORMALIZE_MAGNITUDE
34+
#ifdef EDGE_DETECTOR_LT_EN
35+
int total_number_of_pixels;
36+
int current_number_of_pixels = 0;
37+
int next_target_of_completion = 10.0;
38+
#endif // EDGE_DETECTOR_LT_EN
3439

3540
// Pass command linke arguments
3641
sc_argc();
@@ -56,6 +61,10 @@ int sc_main(int, char*[])
5661

5762
Mat detectedImage(greyImage.rows, greyImage.cols, CV_8UC1);
5863

64+
#ifdef EDGE_DETECTOR_LT_EN
65+
total_number_of_pixels = greyImage.rows * greyImage.cols;
66+
#endif // EDGE_DETECTOR_LT_EN
67+
5968
#ifdef TEST_NORMALIZE_MAGNITUDE
6069
tmpValues = new int*[greyImage.rows];
6170
for (int i = 0; i < greyImage.rows; i++)
@@ -170,6 +179,9 @@ int sc_main(int, char*[])
170179
}
171180

172181
edge_detector.set_local_window(localWindow);
182+
#ifdef EDGE_DETECTOR_LT_EN
183+
sc_start(30, SC_NS);
184+
#endif // EDGE_DETECTOR_LT_EN
173185
localGradientX = edge_detector.obtain_sobel_gradient_x();
174186
localGradientY = edge_detector.obtain_sobel_gradient_y();
175187

@@ -190,6 +202,14 @@ int sc_main(int, char*[])
190202
detectedImage.at<uchar>(i, j) = localResult;
191203
}
192204
#endif // TEST_NORMALIZE_MAGNITUDE
205+
#ifdef EDGE_DETECTOR_LT_EN
206+
current_number_of_pixels++;
207+
if (((((float)(current_number_of_pixels)) / ((float)(total_number_of_pixels))) * 100.0) >= next_target_of_completion)
208+
{
209+
std::cout << "@" << sc_time_stamp() << " Image processing completed at " << next_target_of_completion << std::endl;
210+
next_target_of_completion += 10.0;
211+
}
212+
#endif // EDGE_DETECTOR_LT_EN
193213
}
194214
}
195215

0 commit comments

Comments
 (0)