Skip to content

Commit 890f6e4

Browse files
committed
Load grayscale image instead of the RGB one
Show individual images for each component of the gradient and save them afterwards
1 parent 4da4d98 commit 890f6e4

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

modules/edge-detector/src/tb_edge_detector.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace cv;
2525

2626
int sc_main(int, char*[])
2727
{
28-
Mat greyImage, colorImage;
28+
Mat greyImage;
2929

3030
#ifndef EDGE_DETECTOR_AT_EN
3131
int localWindow[3][3];
@@ -96,18 +96,17 @@ int sc_main(int, char*[])
9696
sc_trace(wf, edge_detector.resultSobelGradientY, "resultSobelGradientY");
9797
#endif // EDGE_DETECTOR_AT_EN
9898

99-
colorImage = imread("../../tools/datagen/src/imgs/car.jpg", IMREAD_UNCHANGED);
99+
greyImage = imread("../../tools/datagen/src/imgs/car_grayscale_image.jpg", IMREAD_GRAYSCALE);
100100

101-
if (colorImage.empty())
101+
if (greyImage.empty())
102102
{
103103
cout << "Image File " << "Not Found" << endl;
104104

105-
// wait for any key press
106-
return -1;
105+
return -1;
107106
}
108107

109-
cvtColor(colorImage, greyImage, cv::COLOR_BGR2GRAY);
110-
108+
Mat detectedImageX(greyImage.rows, greyImage.cols, CV_8UC1);
109+
Mat detectedImageY(greyImage.rows, greyImage.cols, CV_8UC1);
111110
Mat detectedImage(greyImage.rows, greyImage.cols, CV_8UC1);
112111

113112
#if defined(EDGE_DETECTOR_LT_EN) || defined(EDGE_DETECTOR_AT_EN)
@@ -282,6 +281,30 @@ int sc_main(int, char*[])
282281
detectedImage.at<uchar>(i, j) = localResult;
283282
}
284283
#endif // TEST_NORMALIZE_MAGNITUDE
284+
if (localGradientX > 255)
285+
{
286+
detectedImageX.at<uchar>(i, j) = 255;
287+
}
288+
else if (localGradientX < 0)
289+
{
290+
detectedImageX.at<uchar>(i, j) = (-localGradientX);
291+
}
292+
else
293+
{
294+
detectedImageX.at<uchar>(i, j) = localGradientX;
295+
}
296+
if (localGradientY > 255)
297+
{
298+
detectedImageY.at<uchar>(i, j) = 255;
299+
}
300+
else if (localGradientY < 0)
301+
{
302+
detectedImageY.at<uchar>(i, j) = (-localGradientY);
303+
}
304+
else
305+
{
306+
detectedImageY.at<uchar>(i, j) = localGradientY;
307+
}
285308
#if defined(EDGE_DETECTOR_LT_EN) || defined(EDGE_DETECTOR_AT_EN)
286309
current_number_of_pixels++;
287310
if (((((float)(current_number_of_pixels)) / ((float)(total_number_of_pixels))) * 100.0) >= next_target_of_completion)
@@ -303,15 +326,22 @@ int sc_main(int, char*[])
303326
}
304327
#endif // TEST_NORMALIZE_MAGNITUDE
305328

306-
imshow("Window Name", colorImage);
329+
imshow("Original Image", greyImage);
330+
331+
waitKey(0);
332+
333+
imshow("Gradient X", detectedImageX);
334+
imwrite("detectedImageX.jpg", detectedImageX);
307335

308336
waitKey(0);
309337

310-
imshow("Window Name", greyImage);
338+
imshow("Gradient Y", detectedImageY);
339+
imwrite("detectedImageY.jpg", detectedImageY);
311340

312341
waitKey(0);
313342

314-
imshow("Window Name", detectedImage);
343+
imshow("Gradient Total", detectedImage);
344+
imwrite("detectedImage.jpg", detectedImage);
315345

316346
waitKey(0);
317347

0 commit comments

Comments
 (0)