Coverage Report

Created: 2021-04-11 20:23

/home/liu/buildslave/linux-x64-runtests/build/test/unit/basic.tests.c
Line
Count
Source
1
#include "ccv.h"
2
#include "case.h"
3
#include "ccv_case.h"
4
5
TEST_CASE("sobel operation")
6
1
{
7
1
  ccv_dense_matrix_t* image = 0;
8
1
  ccv_read("../../samples/chessbox.png", &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
9
1
  ccv_dense_matrix_t* x = 0;
10
1
  ccv_sobel(image, &x, 0, 0, 1);
11
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.sobel.x.bin", "should be sobel of partial derivative on x");
12
1
  ccv_dense_matrix_t* y = 0;
13
1
  ccv_sobel(image, &y, 0, 1, 0);
14
1
  REQUIRE_MATRIX_FILE_EQ(y, "data/chessbox.sobel.y.bin", "should be sobel of partial derivative on y");
15
1
  ccv_dense_matrix_t* u = 0;
16
1
  ccv_sobel(image, &u, 0, 1, 1);
17
1
  REQUIRE_MATRIX_FILE_EQ(u, "data/chessbox.sobel.u.bin", "should be sobel of derivative along diagonal");
18
1
  ccv_dense_matrix_t* v = 0;
19
1
  ccv_sobel(image, &v, 0, -1, 1);
20
1
  REQUIRE_MATRIX_FILE_EQ(v, "data/chessbox.sobel.v.bin", "should be sobel of derivative along the other diagonal");
21
1
  ccv_dense_matrix_t* x3 = 0;
22
1
  ccv_sobel(image, &x3, 0, 0, 3);
23
1
  REQUIRE_MATRIX_FILE_EQ(x3, "data/chessbox.sobel.x.3.bin", "should be sobel of partial derivative on x within 3x3 window");
24
1
  ccv_dense_matrix_t* y3 = 0;
25
1
  ccv_sobel(image, &y3, 0, 3, 0);
26
1
  REQUIRE_MATRIX_FILE_EQ(y3, "data/chessbox.sobel.y.3.bin", "should be sobel of partial derivative on y within 3x3 window");
27
1
  ccv_dense_matrix_t* x5 = 0;
28
1
  ccv_sobel(image, &x5, 0, 0, 5);
29
1
  REQUIRE_MATRIX_FILE_EQ(x5, "data/chessbox.sobel.x.5.bin", "should be sobel of partial derivative on x within 5x5 window");
30
1
  ccv_dense_matrix_t* y5 = 0;
31
1
  ccv_sobel(image, &y5, 0, 5, 0);
32
1
  REQUIRE_MATRIX_FILE_EQ(y5, "data/chessbox.sobel.y.5.bin", "should be sobel of partial derivative on y within 5x5 window");
33
1
  ccv_matrix_free(image);
34
1
  ccv_matrix_free(x);
35
1
  ccv_matrix_free(y);
36
1
  ccv_matrix_free(u);
37
1
  ccv_matrix_free(v);
38
1
  ccv_matrix_free(x3);
39
1
  ccv_matrix_free(y3);
40
1
  ccv_matrix_free(x5);
41
1
  ccv_matrix_free(y5);
42
1
}
43
44
TEST_CASE("resample operation of CCV_INTER_AREA")
45
1
{
46
1
  ccv_dense_matrix_t* image = 0;
47
1
  ccv_read("../../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
48
1
  ccv_dense_matrix_t* x = 0;
49
1
  ccv_resample(image, &x, 0, image->rows / 5, image->cols / 5, CCV_INTER_AREA);
50
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.resample.bin", "should be a image of color dot");
51
1
  ccv_matrix_free(image);
52
1
  ccv_matrix_free(x);
53
1
}
54
55
TEST_CASE("sample down operation with source offset (10, 10)")
56
1
{
57
1
  ccv_dense_matrix_t* image = 0;
58
1
  ccv_read("../../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
59
1
  ccv_dense_matrix_t* x = 0;
60
1
  ccv_sample_down(image, &x, 0, 10, 10);
61
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.sample_down.bin", "should be down sampled (/2) image with offset from source (10, 10)");
62
1
  ccv_matrix_free(image);
63
1
  ccv_matrix_free(x);
64
1
}
65
66
TEST_CASE("sample up operation with source offset (10, 10)")
67
1
{
68
1
  ccv_dense_matrix_t* image = 0;
69
1
  ccv_read("../../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
70
1
  ccv_dense_matrix_t* x = 0;
71
1
  ccv_sample_up(image, &x, 0, 10, 10);
72
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.sample_up.bin", "should be down sampled (/2) image with offset from source (10, 10)");
73
1
  ccv_matrix_free(image);
74
1
  ccv_matrix_free(x);
75
1
}
76
77
TEST_CASE("blur operation with sigma 10")
78
1
{
79
1
  ccv_dense_matrix_t* image = 0;
80
1
  ccv_read("../../samples/nature.png", &image, CCV_IO_ANY_FILE);
81
1
  ccv_dense_matrix_t* x = 0;
82
1
  ccv_blur(image, &x, 0, sqrt(10));
83
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/nature.blur.bin", "should be image applied with Gaussian filter with sigma sqrt(10)");
84
1
  ccv_matrix_free(image);
85
1
  ccv_matrix_free(x);
86
1
}
87
88
TEST_CASE("flip operation")
89
1
{
90
1
  ccv_dense_matrix_t* image = 0;
91
1
  ccv_read("../../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
92
1
  ccv_dense_matrix_t* x = 0;
93
1
  ccv_flip(image, &x, 0, CCV_FLIP_X);
94
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.flip_x.bin", "flipped x-axis (around y-axis)");
95
1
  ccv_dense_matrix_t* y = 0;
96
1
  ccv_flip(image, &y, 0, CCV_FLIP_Y);
97
1
  REQUIRE_MATRIX_FILE_EQ(y, "data/chessbox.flip_y.bin", "flipped y-axis (around x-axis)");
98
1
  ccv_dense_matrix_t* xy = 0;
99
1
  ccv_flip(image, &xy, 0, CCV_FLIP_X | CCV_FLIP_Y);
100
1
  REQUIRE_MATRIX_FILE_EQ(xy, "data/chessbox.flip_xy.bin", "flipped xy-axis (rotated 180)");
101
1
  ccv_matrix_free(image);
102
1
  ccv_matrix_free(x);
103
1
  ccv_matrix_free(y);
104
1
  ccv_matrix_free(xy);
105
1
}
106
107
TEST_CASE("canny edge detector")
108
1
{
109
1
  ccv_dense_matrix_t* image = 0;
110
1
  ccv_read("../../samples/blackbox.png", &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
111
1
  ccv_dense_matrix_t* x = 0;
112
1
  ccv_canny(image, &x, 0, 3, 36, 36 * 3);
113
1
  REQUIRE_MATRIX_FILE_EQ(x, "data/blackbox.canny.bin", "Canny edge detector on artificial image");
114
1
  ccv_matrix_free(image);
115
1
  ccv_matrix_free(x);
116
1
}
117
118
TEST_CASE("otsu threshold")
119
1
{
120
1
  ccv_dense_matrix_t* image = ccv_dense_matrix_new(6, 6, CCV_32S | CCV_C1, 0, 0);
121
1
  /* the test case is grabbed from: http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html */
122
1
  image->data.i32[0] = image->data.i32[1] = image->data.i32[6] = image->data.i32[22] = image->data.i32[23] = image->data.i32[28] = image->data.i32[29] = image->data.i32[35] = 0;
123
1
  image->data.i32[2] = image->data.i32[7] = image->data.i32[12] = image->data.i32[16] = image->data.i32[21] = image->data.i32[27] = image->data.i32[34] = 1;
124
1
  image->data.i32[15] = image->data.i32[26] = 2;
125
1
  image->data.i32[8] = image->data.i32[10] = image->data.i32[13] = image->data.i32[17] = image->data.i32[20] = image->data.i32[33] = 3;
126
1
  image->data.i32[3] = image->data.i32[4] = image->data.i32[9] = image->data.i32[11] = image->data.i32[14] = image->data.i32[18] = image->data.i32[19] = image->data.i32[25] = image->data.i32[32] = 4;
127
1
  image->data.i32[5] = image->data.i32[24] = image->data.i32[30] = image->data.i32[31] = 5;
128
1
  double var;
129
1
  int threshold = ccv_otsu(image, &var, 6);
130
1
  REQUIRE_EQ(threshold, 2, "threshold should be 2 (inclusive)");
131
1
  REQUIRE_EQ_WITH_TOLERANCE(var, 2.6287, 0.0001, "between class variance should be 2.6287");
132
1
  ccv_matrix_free(image);
133
1
}
134
135
#include "case_main.h"