imagecore 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/ext/imagecore/analyze_image.cxx +58 -0
- data/ext/imagecore/analyze_image.h +6 -0
- data/ext/imagecore/extconf.rb +9 -0
- data/ext/imagecore/imagecore.cxx +34 -0
- data/ext/opencv/core/___.c +3 -0
- data/ext/opencv/core/alloc.cpp +697 -0
- data/ext/opencv/core/array.cpp +3206 -0
- data/ext/opencv/core/datastructs.cpp +4064 -0
- data/ext/opencv/core/extconf.rb +22 -0
- data/ext/opencv/core/matrix.cpp +3777 -0
- data/ext/opencv/core/precomp.hpp +216 -0
- data/ext/opencv/core/system.cpp +832 -0
- data/ext/opencv/core/tables.cpp +3512 -0
- data/ext/opencv/highgui/___.c +3 -0
- data/ext/opencv/highgui/bitstrm.cpp +582 -0
- data/ext/opencv/highgui/bitstrm.hpp +182 -0
- data/ext/opencv/highgui/extconf.rb +28 -0
- data/ext/opencv/highgui/grfmt_base.cpp +128 -0
- data/ext/opencv/highgui/grfmt_base.hpp +113 -0
- data/ext/opencv/highgui/grfmt_bmp.cpp +564 -0
- data/ext/opencv/highgui/grfmt_bmp.hpp +99 -0
- data/ext/opencv/highgui/grfmt_exr.hpp +113 -0
- data/ext/opencv/highgui/grfmt_imageio.hpp +56 -0
- data/ext/opencv/highgui/grfmt_jpeg.cpp +622 -0
- data/ext/opencv/highgui/grfmt_jpeg.hpp +90 -0
- data/ext/opencv/highgui/grfmt_jpeg2000.cpp +529 -0
- data/ext/opencv/highgui/grfmt_jpeg2000.hpp +95 -0
- data/ext/opencv/highgui/grfmt_png.cpp +406 -0
- data/ext/opencv/highgui/grfmt_png.hpp +101 -0
- data/ext/opencv/highgui/grfmt_pxm.cpp +513 -0
- data/ext/opencv/highgui/grfmt_pxm.hpp +92 -0
- data/ext/opencv/highgui/grfmt_sunras.cpp +425 -0
- data/ext/opencv/highgui/grfmt_sunras.hpp +105 -0
- data/ext/opencv/highgui/grfmt_tiff.cpp +718 -0
- data/ext/opencv/highgui/grfmt_tiff.hpp +136 -0
- data/ext/opencv/highgui/grfmts.hpp +56 -0
- data/ext/opencv/highgui/loadsave.cpp +535 -0
- data/ext/opencv/highgui/precomp.hpp +223 -0
- data/ext/opencv/highgui/utils.cpp +689 -0
- data/ext/opencv/highgui/utils.hpp +128 -0
- data/ext/opencv/imgproc/___.c +3 -0
- data/ext/opencv/imgproc/_geom.h +72 -0
- data/ext/opencv/imgproc/color.cpp +3179 -0
- data/ext/opencv/imgproc/contours.cpp +1780 -0
- data/ext/opencv/imgproc/extconf.rb +11 -0
- data/ext/opencv/imgproc/filter.cpp +3063 -0
- data/ext/opencv/imgproc/precomp.hpp +159 -0
- data/ext/opencv/imgproc/shapedescr.cpp +1306 -0
- data/ext/opencv/imgproc/smooth.cpp +1566 -0
- data/ext/opencv/imgproc/tables.cpp +214 -0
- data/ext/opencv/imgproc/thresh.cpp +636 -0
- data/ext/opencv/imgproc/utils.cpp +242 -0
- data/ext/opencv/include/opencv2/core/core.hpp +4344 -0
- data/ext/opencv/include/opencv2/core/core_c.h +1885 -0
- data/ext/opencv/include/opencv2/core/internal.hpp +710 -0
- data/ext/opencv/include/opencv2/core/mat.hpp +2557 -0
- data/ext/opencv/include/opencv2/core/operations.hpp +3623 -0
- data/ext/opencv/include/opencv2/core/types_c.h +1875 -0
- data/ext/opencv/include/opencv2/core/version.hpp +58 -0
- data/ext/opencv/include/opencv2/highgui/highgui.hpp +198 -0
- data/ext/opencv/include/opencv2/highgui/highgui_c.h +506 -0
- data/ext/opencv/include/opencv2/imgproc/imgproc.hpp +1139 -0
- data/ext/opencv/include/opencv2/imgproc/imgproc_c.h +783 -0
- data/ext/opencv/include/opencv2/imgproc/types_c.h +538 -0
- data/imagecore.gemspec +20 -0
- data/lib/imagecore.rb +16 -0
- data/lib/imagecore/version.rb +3 -0
- metadata +119 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
/* ////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// CvMat helper tables
|
4
|
+
//
|
5
|
+
// */
|
6
|
+
|
7
|
+
#include "precomp.hpp"
|
8
|
+
|
9
|
+
const float icv8x32fTab_cv[] =
|
10
|
+
{
|
11
|
+
-256.f, -255.f, -254.f, -253.f, -252.f, -251.f, -250.f, -249.f,
|
12
|
+
-248.f, -247.f, -246.f, -245.f, -244.f, -243.f, -242.f, -241.f,
|
13
|
+
-240.f, -239.f, -238.f, -237.f, -236.f, -235.f, -234.f, -233.f,
|
14
|
+
-232.f, -231.f, -230.f, -229.f, -228.f, -227.f, -226.f, -225.f,
|
15
|
+
-224.f, -223.f, -222.f, -221.f, -220.f, -219.f, -218.f, -217.f,
|
16
|
+
-216.f, -215.f, -214.f, -213.f, -212.f, -211.f, -210.f, -209.f,
|
17
|
+
-208.f, -207.f, -206.f, -205.f, -204.f, -203.f, -202.f, -201.f,
|
18
|
+
-200.f, -199.f, -198.f, -197.f, -196.f, -195.f, -194.f, -193.f,
|
19
|
+
-192.f, -191.f, -190.f, -189.f, -188.f, -187.f, -186.f, -185.f,
|
20
|
+
-184.f, -183.f, -182.f, -181.f, -180.f, -179.f, -178.f, -177.f,
|
21
|
+
-176.f, -175.f, -174.f, -173.f, -172.f, -171.f, -170.f, -169.f,
|
22
|
+
-168.f, -167.f, -166.f, -165.f, -164.f, -163.f, -162.f, -161.f,
|
23
|
+
-160.f, -159.f, -158.f, -157.f, -156.f, -155.f, -154.f, -153.f,
|
24
|
+
-152.f, -151.f, -150.f, -149.f, -148.f, -147.f, -146.f, -145.f,
|
25
|
+
-144.f, -143.f, -142.f, -141.f, -140.f, -139.f, -138.f, -137.f,
|
26
|
+
-136.f, -135.f, -134.f, -133.f, -132.f, -131.f, -130.f, -129.f,
|
27
|
+
-128.f, -127.f, -126.f, -125.f, -124.f, -123.f, -122.f, -121.f,
|
28
|
+
-120.f, -119.f, -118.f, -117.f, -116.f, -115.f, -114.f, -113.f,
|
29
|
+
-112.f, -111.f, -110.f, -109.f, -108.f, -107.f, -106.f, -105.f,
|
30
|
+
-104.f, -103.f, -102.f, -101.f, -100.f, -99.f, -98.f, -97.f,
|
31
|
+
-96.f, -95.f, -94.f, -93.f, -92.f, -91.f, -90.f, -89.f,
|
32
|
+
-88.f, -87.f, -86.f, -85.f, -84.f, -83.f, -82.f, -81.f,
|
33
|
+
-80.f, -79.f, -78.f, -77.f, -76.f, -75.f, -74.f, -73.f,
|
34
|
+
-72.f, -71.f, -70.f, -69.f, -68.f, -67.f, -66.f, -65.f,
|
35
|
+
-64.f, -63.f, -62.f, -61.f, -60.f, -59.f, -58.f, -57.f,
|
36
|
+
-56.f, -55.f, -54.f, -53.f, -52.f, -51.f, -50.f, -49.f,
|
37
|
+
-48.f, -47.f, -46.f, -45.f, -44.f, -43.f, -42.f, -41.f,
|
38
|
+
-40.f, -39.f, -38.f, -37.f, -36.f, -35.f, -34.f, -33.f,
|
39
|
+
-32.f, -31.f, -30.f, -29.f, -28.f, -27.f, -26.f, -25.f,
|
40
|
+
-24.f, -23.f, -22.f, -21.f, -20.f, -19.f, -18.f, -17.f,
|
41
|
+
-16.f, -15.f, -14.f, -13.f, -12.f, -11.f, -10.f, -9.f,
|
42
|
+
-8.f, -7.f, -6.f, -5.f, -4.f, -3.f, -2.f, -1.f,
|
43
|
+
0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f,
|
44
|
+
8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f,
|
45
|
+
16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f,
|
46
|
+
24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f,
|
47
|
+
32.f, 33.f, 34.f, 35.f, 36.f, 37.f, 38.f, 39.f,
|
48
|
+
40.f, 41.f, 42.f, 43.f, 44.f, 45.f, 46.f, 47.f,
|
49
|
+
48.f, 49.f, 50.f, 51.f, 52.f, 53.f, 54.f, 55.f,
|
50
|
+
56.f, 57.f, 58.f, 59.f, 60.f, 61.f, 62.f, 63.f,
|
51
|
+
64.f, 65.f, 66.f, 67.f, 68.f, 69.f, 70.f, 71.f,
|
52
|
+
72.f, 73.f, 74.f, 75.f, 76.f, 77.f, 78.f, 79.f,
|
53
|
+
80.f, 81.f, 82.f, 83.f, 84.f, 85.f, 86.f, 87.f,
|
54
|
+
88.f, 89.f, 90.f, 91.f, 92.f, 93.f, 94.f, 95.f,
|
55
|
+
96.f, 97.f, 98.f, 99.f, 100.f, 101.f, 102.f, 103.f,
|
56
|
+
104.f, 105.f, 106.f, 107.f, 108.f, 109.f, 110.f, 111.f,
|
57
|
+
112.f, 113.f, 114.f, 115.f, 116.f, 117.f, 118.f, 119.f,
|
58
|
+
120.f, 121.f, 122.f, 123.f, 124.f, 125.f, 126.f, 127.f,
|
59
|
+
128.f, 129.f, 130.f, 131.f, 132.f, 133.f, 134.f, 135.f,
|
60
|
+
136.f, 137.f, 138.f, 139.f, 140.f, 141.f, 142.f, 143.f,
|
61
|
+
144.f, 145.f, 146.f, 147.f, 148.f, 149.f, 150.f, 151.f,
|
62
|
+
152.f, 153.f, 154.f, 155.f, 156.f, 157.f, 158.f, 159.f,
|
63
|
+
160.f, 161.f, 162.f, 163.f, 164.f, 165.f, 166.f, 167.f,
|
64
|
+
168.f, 169.f, 170.f, 171.f, 172.f, 173.f, 174.f, 175.f,
|
65
|
+
176.f, 177.f, 178.f, 179.f, 180.f, 181.f, 182.f, 183.f,
|
66
|
+
184.f, 185.f, 186.f, 187.f, 188.f, 189.f, 190.f, 191.f,
|
67
|
+
192.f, 193.f, 194.f, 195.f, 196.f, 197.f, 198.f, 199.f,
|
68
|
+
200.f, 201.f, 202.f, 203.f, 204.f, 205.f, 206.f, 207.f,
|
69
|
+
208.f, 209.f, 210.f, 211.f, 212.f, 213.f, 214.f, 215.f,
|
70
|
+
216.f, 217.f, 218.f, 219.f, 220.f, 221.f, 222.f, 223.f,
|
71
|
+
224.f, 225.f, 226.f, 227.f, 228.f, 229.f, 230.f, 231.f,
|
72
|
+
232.f, 233.f, 234.f, 235.f, 236.f, 237.f, 238.f, 239.f,
|
73
|
+
240.f, 241.f, 242.f, 243.f, 244.f, 245.f, 246.f, 247.f,
|
74
|
+
248.f, 249.f, 250.f, 251.f, 252.f, 253.f, 254.f, 255.f,
|
75
|
+
256.f, 257.f, 258.f, 259.f, 260.f, 261.f, 262.f, 263.f,
|
76
|
+
264.f, 265.f, 266.f, 267.f, 268.f, 269.f, 270.f, 271.f,
|
77
|
+
272.f, 273.f, 274.f, 275.f, 276.f, 277.f, 278.f, 279.f,
|
78
|
+
280.f, 281.f, 282.f, 283.f, 284.f, 285.f, 286.f, 287.f,
|
79
|
+
288.f, 289.f, 290.f, 291.f, 292.f, 293.f, 294.f, 295.f,
|
80
|
+
296.f, 297.f, 298.f, 299.f, 300.f, 301.f, 302.f, 303.f,
|
81
|
+
304.f, 305.f, 306.f, 307.f, 308.f, 309.f, 310.f, 311.f,
|
82
|
+
312.f, 313.f, 314.f, 315.f, 316.f, 317.f, 318.f, 319.f,
|
83
|
+
320.f, 321.f, 322.f, 323.f, 324.f, 325.f, 326.f, 327.f,
|
84
|
+
328.f, 329.f, 330.f, 331.f, 332.f, 333.f, 334.f, 335.f,
|
85
|
+
336.f, 337.f, 338.f, 339.f, 340.f, 341.f, 342.f, 343.f,
|
86
|
+
344.f, 345.f, 346.f, 347.f, 348.f, 349.f, 350.f, 351.f,
|
87
|
+
352.f, 353.f, 354.f, 355.f, 356.f, 357.f, 358.f, 359.f,
|
88
|
+
360.f, 361.f, 362.f, 363.f, 364.f, 365.f, 366.f, 367.f,
|
89
|
+
368.f, 369.f, 370.f, 371.f, 372.f, 373.f, 374.f, 375.f,
|
90
|
+
376.f, 377.f, 378.f, 379.f, 380.f, 381.f, 382.f, 383.f,
|
91
|
+
384.f, 385.f, 386.f, 387.f, 388.f, 389.f, 390.f, 391.f,
|
92
|
+
392.f, 393.f, 394.f, 395.f, 396.f, 397.f, 398.f, 399.f,
|
93
|
+
400.f, 401.f, 402.f, 403.f, 404.f, 405.f, 406.f, 407.f,
|
94
|
+
408.f, 409.f, 410.f, 411.f, 412.f, 413.f, 414.f, 415.f,
|
95
|
+
416.f, 417.f, 418.f, 419.f, 420.f, 421.f, 422.f, 423.f,
|
96
|
+
424.f, 425.f, 426.f, 427.f, 428.f, 429.f, 430.f, 431.f,
|
97
|
+
432.f, 433.f, 434.f, 435.f, 436.f, 437.f, 438.f, 439.f,
|
98
|
+
440.f, 441.f, 442.f, 443.f, 444.f, 445.f, 446.f, 447.f,
|
99
|
+
448.f, 449.f, 450.f, 451.f, 452.f, 453.f, 454.f, 455.f,
|
100
|
+
456.f, 457.f, 458.f, 459.f, 460.f, 461.f, 462.f, 463.f,
|
101
|
+
464.f, 465.f, 466.f, 467.f, 468.f, 469.f, 470.f, 471.f,
|
102
|
+
472.f, 473.f, 474.f, 475.f, 476.f, 477.f, 478.f, 479.f,
|
103
|
+
480.f, 481.f, 482.f, 483.f, 484.f, 485.f, 486.f, 487.f,
|
104
|
+
488.f, 489.f, 490.f, 491.f, 492.f, 493.f, 494.f, 495.f,
|
105
|
+
496.f, 497.f, 498.f, 499.f, 500.f, 501.f, 502.f, 503.f,
|
106
|
+
504.f, 505.f, 506.f, 507.f, 508.f, 509.f, 510.f, 511.f,
|
107
|
+
};
|
108
|
+
|
109
|
+
const float icv8x32fSqrTab[] =
|
110
|
+
{
|
111
|
+
16384.f, 16129.f, 15876.f, 15625.f, 15376.f, 15129.f, 14884.f, 14641.f,
|
112
|
+
14400.f, 14161.f, 13924.f, 13689.f, 13456.f, 13225.f, 12996.f, 12769.f,
|
113
|
+
12544.f, 12321.f, 12100.f, 11881.f, 11664.f, 11449.f, 11236.f, 11025.f,
|
114
|
+
10816.f, 10609.f, 10404.f, 10201.f, 10000.f, 9801.f, 9604.f, 9409.f,
|
115
|
+
9216.f, 9025.f, 8836.f, 8649.f, 8464.f, 8281.f, 8100.f, 7921.f,
|
116
|
+
7744.f, 7569.f, 7396.f, 7225.f, 7056.f, 6889.f, 6724.f, 6561.f,
|
117
|
+
6400.f, 6241.f, 6084.f, 5929.f, 5776.f, 5625.f, 5476.f, 5329.f,
|
118
|
+
5184.f, 5041.f, 4900.f, 4761.f, 4624.f, 4489.f, 4356.f, 4225.f,
|
119
|
+
4096.f, 3969.f, 3844.f, 3721.f, 3600.f, 3481.f, 3364.f, 3249.f,
|
120
|
+
3136.f, 3025.f, 2916.f, 2809.f, 2704.f, 2601.f, 2500.f, 2401.f,
|
121
|
+
2304.f, 2209.f, 2116.f, 2025.f, 1936.f, 1849.f, 1764.f, 1681.f,
|
122
|
+
1600.f, 1521.f, 1444.f, 1369.f, 1296.f, 1225.f, 1156.f, 1089.f,
|
123
|
+
1024.f, 961.f, 900.f, 841.f, 784.f, 729.f, 676.f, 625.f,
|
124
|
+
576.f, 529.f, 484.f, 441.f, 400.f, 361.f, 324.f, 289.f,
|
125
|
+
256.f, 225.f, 196.f, 169.f, 144.f, 121.f, 100.f, 81.f,
|
126
|
+
64.f, 49.f, 36.f, 25.f, 16.f, 9.f, 4.f, 1.f,
|
127
|
+
0.f, 1.f, 4.f, 9.f, 16.f, 25.f, 36.f, 49.f,
|
128
|
+
64.f, 81.f, 100.f, 121.f, 144.f, 169.f, 196.f, 225.f,
|
129
|
+
256.f, 289.f, 324.f, 361.f, 400.f, 441.f, 484.f, 529.f,
|
130
|
+
576.f, 625.f, 676.f, 729.f, 784.f, 841.f, 900.f, 961.f,
|
131
|
+
1024.f, 1089.f, 1156.f, 1225.f, 1296.f, 1369.f, 1444.f, 1521.f,
|
132
|
+
1600.f, 1681.f, 1764.f, 1849.f, 1936.f, 2025.f, 2116.f, 2209.f,
|
133
|
+
2304.f, 2401.f, 2500.f, 2601.f, 2704.f, 2809.f, 2916.f, 3025.f,
|
134
|
+
3136.f, 3249.f, 3364.f, 3481.f, 3600.f, 3721.f, 3844.f, 3969.f,
|
135
|
+
4096.f, 4225.f, 4356.f, 4489.f, 4624.f, 4761.f, 4900.f, 5041.f,
|
136
|
+
5184.f, 5329.f, 5476.f, 5625.f, 5776.f, 5929.f, 6084.f, 6241.f,
|
137
|
+
6400.f, 6561.f, 6724.f, 6889.f, 7056.f, 7225.f, 7396.f, 7569.f,
|
138
|
+
7744.f, 7921.f, 8100.f, 8281.f, 8464.f, 8649.f, 8836.f, 9025.f,
|
139
|
+
9216.f, 9409.f, 9604.f, 9801.f, 10000.f, 10201.f, 10404.f, 10609.f,
|
140
|
+
10816.f, 11025.f, 11236.f, 11449.f, 11664.f, 11881.f, 12100.f, 12321.f,
|
141
|
+
12544.f, 12769.f, 12996.f, 13225.f, 13456.f, 13689.f, 13924.f, 14161.f,
|
142
|
+
14400.f, 14641.f, 14884.f, 15129.f, 15376.f, 15625.f, 15876.f, 16129.f,
|
143
|
+
16384.f, 16641.f, 16900.f, 17161.f, 17424.f, 17689.f, 17956.f, 18225.f,
|
144
|
+
18496.f, 18769.f, 19044.f, 19321.f, 19600.f, 19881.f, 20164.f, 20449.f,
|
145
|
+
20736.f, 21025.f, 21316.f, 21609.f, 21904.f, 22201.f, 22500.f, 22801.f,
|
146
|
+
23104.f, 23409.f, 23716.f, 24025.f, 24336.f, 24649.f, 24964.f, 25281.f,
|
147
|
+
25600.f, 25921.f, 26244.f, 26569.f, 26896.f, 27225.f, 27556.f, 27889.f,
|
148
|
+
28224.f, 28561.f, 28900.f, 29241.f, 29584.f, 29929.f, 30276.f, 30625.f,
|
149
|
+
30976.f, 31329.f, 31684.f, 32041.f, 32400.f, 32761.f, 33124.f, 33489.f,
|
150
|
+
33856.f, 34225.f, 34596.f, 34969.f, 35344.f, 35721.f, 36100.f, 36481.f,
|
151
|
+
36864.f, 37249.f, 37636.f, 38025.f, 38416.f, 38809.f, 39204.f, 39601.f,
|
152
|
+
40000.f, 40401.f, 40804.f, 41209.f, 41616.f, 42025.f, 42436.f, 42849.f,
|
153
|
+
43264.f, 43681.f, 44100.f, 44521.f, 44944.f, 45369.f, 45796.f, 46225.f,
|
154
|
+
46656.f, 47089.f, 47524.f, 47961.f, 48400.f, 48841.f, 49284.f, 49729.f,
|
155
|
+
50176.f, 50625.f, 51076.f, 51529.f, 51984.f, 52441.f, 52900.f, 53361.f,
|
156
|
+
53824.f, 54289.f, 54756.f, 55225.f, 55696.f, 56169.f, 56644.f, 57121.f,
|
157
|
+
57600.f, 58081.f, 58564.f, 59049.f, 59536.f, 60025.f, 60516.f, 61009.f,
|
158
|
+
61504.f, 62001.f, 62500.f, 63001.f, 63504.f, 64009.f, 64516.f, 65025.f
|
159
|
+
};
|
160
|
+
|
161
|
+
const uchar icvSaturate8u_cv[] =
|
162
|
+
{
|
163
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
164
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
165
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
166
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
167
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
168
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
169
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
170
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
171
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
172
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
173
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
174
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
175
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
176
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
177
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
178
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
179
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
180
|
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
181
|
+
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
182
|
+
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
183
|
+
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
184
|
+
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
185
|
+
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
|
186
|
+
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
|
187
|
+
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
|
188
|
+
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
|
189
|
+
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
|
190
|
+
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
|
191
|
+
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
|
192
|
+
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
|
193
|
+
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
|
194
|
+
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
|
195
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
196
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
197
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
198
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
199
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
200
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
201
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
202
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
203
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
204
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
205
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
206
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
207
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
208
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
209
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
210
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
211
|
+
255
|
212
|
+
};
|
213
|
+
|
214
|
+
/* End of file. */
|
@@ -0,0 +1,636 @@
|
|
1
|
+
/*M///////////////////////////////////////////////////////////////////////////////////////
|
2
|
+
//
|
3
|
+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
4
|
+
//
|
5
|
+
// By downloading, copying, installing or using the software you agree to this license.
|
6
|
+
// If you do not agree to this license, do not download, install,
|
7
|
+
// copy or use the software.
|
8
|
+
//
|
9
|
+
//
|
10
|
+
// License Agreement
|
11
|
+
// For Open Source Computer Vision Library
|
12
|
+
//
|
13
|
+
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
14
|
+
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
15
|
+
// Third party copyrights are property of their respective owners.
|
16
|
+
//
|
17
|
+
// Redistribution and use in source and binary forms, with or without modification,
|
18
|
+
// are permitted provided that the following conditions are met:
|
19
|
+
//
|
20
|
+
// * Redistribution's of source code must retain the above copyright notice,
|
21
|
+
// this list of conditions and the following disclaimer.
|
22
|
+
//
|
23
|
+
// * Redistribution's in binary form must reproduce the above copyright notice,
|
24
|
+
// this list of conditions and the following disclaimer in the documentation
|
25
|
+
// and/or other materials provided with the distribution.
|
26
|
+
//
|
27
|
+
// * The name of the copyright holders may not be used to endorse or promote products
|
28
|
+
// derived from this software without specific prior written permission.
|
29
|
+
//
|
30
|
+
// This software is provided by the copyright holders and contributors "as is" and
|
31
|
+
// any express or implied warranties, including, but not limited to, the implied
|
32
|
+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
33
|
+
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
34
|
+
// indirect, incidental, special, exemplary, or consequential damages
|
35
|
+
// (including, but not limited to, procurement of substitute goods or services;
|
36
|
+
// loss of use, data, or profits; or business interruption) however caused
|
37
|
+
// and on any theory of liability, whether in contract, strict liability,
|
38
|
+
// or tort (including negligence or otherwise) arising in any way out of
|
39
|
+
// the use of this software, even if advised of the possibility of such damage.
|
40
|
+
//
|
41
|
+
//M*/
|
42
|
+
|
43
|
+
#include "precomp.hpp"
|
44
|
+
|
45
|
+
namespace cv
|
46
|
+
{
|
47
|
+
|
48
|
+
static void
|
49
|
+
thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type )
|
50
|
+
{
|
51
|
+
int i, j, j_scalar = 0;
|
52
|
+
uchar tab[256];
|
53
|
+
Size roi = _src.size();
|
54
|
+
roi.width *= _src.channels();
|
55
|
+
|
56
|
+
if( _src.isContinuous() && _dst.isContinuous() )
|
57
|
+
{
|
58
|
+
roi.width *= roi.height;
|
59
|
+
roi.height = 1;
|
60
|
+
}
|
61
|
+
|
62
|
+
#ifdef HAVE_TEGRA_OPTIMIZATION
|
63
|
+
switch( type )
|
64
|
+
{
|
65
|
+
case THRESH_BINARY:
|
66
|
+
if(tegra::thresh_8u_binary(_src, _dst, roi.width, roi.height, thresh, maxval)) return;
|
67
|
+
break;
|
68
|
+
case THRESH_BINARY_INV:
|
69
|
+
if(tegra::thresh_8u_binary_inv(_src, _dst, roi.width, roi.height, thresh, maxval)) return;
|
70
|
+
break;
|
71
|
+
case THRESH_TRUNC:
|
72
|
+
if(tegra::thresh_8u_trunc(_src, _dst, roi.width, roi.height, thresh)) return;
|
73
|
+
break;
|
74
|
+
case THRESH_TOZERO:
|
75
|
+
if(tegra::thresh_8u_tozero(_src, _dst, roi.width, roi.height, thresh)) return;
|
76
|
+
break;
|
77
|
+
case THRESH_TOZERO_INV:
|
78
|
+
if(tegra::thresh_8u_tozero_inv(_src, _dst, roi.width, roi.height, thresh)) return;
|
79
|
+
break;
|
80
|
+
}
|
81
|
+
#endif
|
82
|
+
|
83
|
+
switch( type )
|
84
|
+
{
|
85
|
+
case THRESH_BINARY:
|
86
|
+
for( i = 0; i <= thresh; i++ )
|
87
|
+
tab[i] = 0;
|
88
|
+
for( ; i < 256; i++ )
|
89
|
+
tab[i] = maxval;
|
90
|
+
break;
|
91
|
+
case THRESH_BINARY_INV:
|
92
|
+
for( i = 0; i <= thresh; i++ )
|
93
|
+
tab[i] = maxval;
|
94
|
+
for( ; i < 256; i++ )
|
95
|
+
tab[i] = 0;
|
96
|
+
break;
|
97
|
+
case THRESH_TRUNC:
|
98
|
+
for( i = 0; i <= thresh; i++ )
|
99
|
+
tab[i] = (uchar)i;
|
100
|
+
for( ; i < 256; i++ )
|
101
|
+
tab[i] = thresh;
|
102
|
+
break;
|
103
|
+
case THRESH_TOZERO:
|
104
|
+
for( i = 0; i <= thresh; i++ )
|
105
|
+
tab[i] = 0;
|
106
|
+
for( ; i < 256; i++ )
|
107
|
+
tab[i] = (uchar)i;
|
108
|
+
break;
|
109
|
+
case THRESH_TOZERO_INV:
|
110
|
+
for( i = 0; i <= thresh; i++ )
|
111
|
+
tab[i] = (uchar)i;
|
112
|
+
for( ; i < 256; i++ )
|
113
|
+
tab[i] = 0;
|
114
|
+
break;
|
115
|
+
default:
|
116
|
+
CV_Error( CV_StsBadArg, "Unknown threshold type" );
|
117
|
+
}
|
118
|
+
|
119
|
+
#if CV_SSE2
|
120
|
+
if( checkHardwareSupport(CV_CPU_SSE2) )
|
121
|
+
{
|
122
|
+
__m128i _x80 = _mm_set1_epi8('\x80');
|
123
|
+
__m128i thresh_u = _mm_set1_epi8(thresh);
|
124
|
+
__m128i thresh_s = _mm_set1_epi8(thresh ^ 0x80);
|
125
|
+
__m128i maxval_ = _mm_set1_epi8(maxval);
|
126
|
+
j_scalar = roi.width & -8;
|
127
|
+
|
128
|
+
for( i = 0; i < roi.height; i++ )
|
129
|
+
{
|
130
|
+
const uchar* src = (const uchar*)(_src.data + _src.step*i);
|
131
|
+
uchar* dst = (uchar*)(_dst.data + _dst.step*i);
|
132
|
+
|
133
|
+
switch( type )
|
134
|
+
{
|
135
|
+
case THRESH_BINARY:
|
136
|
+
for( j = 0; j <= roi.width - 32; j += 32 )
|
137
|
+
{
|
138
|
+
__m128i v0, v1;
|
139
|
+
v0 = _mm_loadu_si128( (const __m128i*)(src + j) );
|
140
|
+
v1 = _mm_loadu_si128( (const __m128i*)(src + j + 16) );
|
141
|
+
v0 = _mm_cmpgt_epi8( _mm_xor_si128(v0, _x80), thresh_s );
|
142
|
+
v1 = _mm_cmpgt_epi8( _mm_xor_si128(v1, _x80), thresh_s );
|
143
|
+
v0 = _mm_and_si128( v0, maxval_ );
|
144
|
+
v1 = _mm_and_si128( v1, maxval_ );
|
145
|
+
_mm_storeu_si128( (__m128i*)(dst + j), v0 );
|
146
|
+
_mm_storeu_si128( (__m128i*)(dst + j + 16), v1 );
|
147
|
+
}
|
148
|
+
|
149
|
+
for( ; j <= roi.width - 8; j += 8 )
|
150
|
+
{
|
151
|
+
__m128i v0 = _mm_loadl_epi64( (const __m128i*)(src + j) );
|
152
|
+
v0 = _mm_cmpgt_epi8( _mm_xor_si128(v0, _x80), thresh_s );
|
153
|
+
v0 = _mm_and_si128( v0, maxval_ );
|
154
|
+
_mm_storel_epi64( (__m128i*)(dst + j), v0 );
|
155
|
+
}
|
156
|
+
break;
|
157
|
+
|
158
|
+
case THRESH_BINARY_INV:
|
159
|
+
for( j = 0; j <= roi.width - 32; j += 32 )
|
160
|
+
{
|
161
|
+
__m128i v0, v1;
|
162
|
+
v0 = _mm_loadu_si128( (const __m128i*)(src + j) );
|
163
|
+
v1 = _mm_loadu_si128( (const __m128i*)(src + j + 16) );
|
164
|
+
v0 = _mm_cmpgt_epi8( _mm_xor_si128(v0, _x80), thresh_s );
|
165
|
+
v1 = _mm_cmpgt_epi8( _mm_xor_si128(v1, _x80), thresh_s );
|
166
|
+
v0 = _mm_andnot_si128( v0, maxval_ );
|
167
|
+
v1 = _mm_andnot_si128( v1, maxval_ );
|
168
|
+
_mm_storeu_si128( (__m128i*)(dst + j), v0 );
|
169
|
+
_mm_storeu_si128( (__m128i*)(dst + j + 16), v1 );
|
170
|
+
}
|
171
|
+
|
172
|
+
for( ; j <= roi.width - 8; j += 8 )
|
173
|
+
{
|
174
|
+
__m128i v0 = _mm_loadl_epi64( (const __m128i*)(src + j) );
|
175
|
+
v0 = _mm_cmpgt_epi8( _mm_xor_si128(v0, _x80), thresh_s );
|
176
|
+
v0 = _mm_andnot_si128( v0, maxval_ );
|
177
|
+
_mm_storel_epi64( (__m128i*)(dst + j), v0 );
|
178
|
+
}
|
179
|
+
break;
|
180
|
+
|
181
|
+
case THRESH_TRUNC:
|
182
|
+
for( j = 0; j <= roi.width - 32; j += 32 )
|
183
|
+
{
|
184
|
+
__m128i v0, v1;
|
185
|
+
v0 = _mm_loadu_si128( (const __m128i*)(src + j) );
|
186
|
+
v1 = _mm_loadu_si128( (const __m128i*)(src + j + 16) );
|
187
|
+
v0 = _mm_subs_epu8( v0, _mm_subs_epu8( v0, thresh_u ));
|
188
|
+
v1 = _mm_subs_epu8( v1, _mm_subs_epu8( v1, thresh_u ));
|
189
|
+
_mm_storeu_si128( (__m128i*)(dst + j), v0 );
|
190
|
+
_mm_storeu_si128( (__m128i*)(dst + j + 16), v1 );
|
191
|
+
}
|
192
|
+
|
193
|
+
for( ; j <= roi.width - 8; j += 8 )
|
194
|
+
{
|
195
|
+
__m128i v0 = _mm_loadl_epi64( (const __m128i*)(src + j) );
|
196
|
+
v0 = _mm_subs_epu8( v0, _mm_subs_epu8( v0, thresh_u ));
|
197
|
+
_mm_storel_epi64( (__m128i*)(dst + j), v0 );
|
198
|
+
}
|
199
|
+
break;
|
200
|
+
|
201
|
+
case THRESH_TOZERO:
|
202
|
+
for( j = 0; j <= roi.width - 32; j += 32 )
|
203
|
+
{
|
204
|
+
__m128i v0, v1;
|
205
|
+
v0 = _mm_loadu_si128( (const __m128i*)(src + j) );
|
206
|
+
v1 = _mm_loadu_si128( (const __m128i*)(src + j + 16) );
|
207
|
+
v0 = _mm_and_si128( v0, _mm_cmpgt_epi8(_mm_xor_si128(v0, _x80), thresh_s ));
|
208
|
+
v1 = _mm_and_si128( v1, _mm_cmpgt_epi8(_mm_xor_si128(v1, _x80), thresh_s ));
|
209
|
+
_mm_storeu_si128( (__m128i*)(dst + j), v0 );
|
210
|
+
_mm_storeu_si128( (__m128i*)(dst + j + 16), v1 );
|
211
|
+
}
|
212
|
+
|
213
|
+
for( ; j <= roi.width - 8; j += 8 )
|
214
|
+
{
|
215
|
+
__m128i v0 = _mm_loadl_epi64( (const __m128i*)(src + j) );
|
216
|
+
v0 = _mm_and_si128( v0, _mm_cmpgt_epi8(_mm_xor_si128(v0, _x80), thresh_s ));
|
217
|
+
_mm_storel_epi64( (__m128i*)(dst + j), v0 );
|
218
|
+
}
|
219
|
+
break;
|
220
|
+
|
221
|
+
case THRESH_TOZERO_INV:
|
222
|
+
for( j = 0; j <= roi.width - 32; j += 32 )
|
223
|
+
{
|
224
|
+
__m128i v0, v1;
|
225
|
+
v0 = _mm_loadu_si128( (const __m128i*)(src + j) );
|
226
|
+
v1 = _mm_loadu_si128( (const __m128i*)(src + j + 16) );
|
227
|
+
v0 = _mm_andnot_si128( _mm_cmpgt_epi8(_mm_xor_si128(v0, _x80), thresh_s ), v0 );
|
228
|
+
v1 = _mm_andnot_si128( _mm_cmpgt_epi8(_mm_xor_si128(v1, _x80), thresh_s ), v1 );
|
229
|
+
_mm_storeu_si128( (__m128i*)(dst + j), v0 );
|
230
|
+
_mm_storeu_si128( (__m128i*)(dst + j + 16), v1 );
|
231
|
+
}
|
232
|
+
|
233
|
+
for( ; j <= roi.width - 8; j += 8 )
|
234
|
+
{
|
235
|
+
__m128i v0 = _mm_loadl_epi64( (const __m128i*)(src + j) );
|
236
|
+
v0 = _mm_andnot_si128( _mm_cmpgt_epi8(_mm_xor_si128(v0, _x80), thresh_s ), v0 );
|
237
|
+
_mm_storel_epi64( (__m128i*)(dst + j), v0 );
|
238
|
+
}
|
239
|
+
break;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
}
|
243
|
+
#endif
|
244
|
+
|
245
|
+
if( j_scalar < roi.width )
|
246
|
+
{
|
247
|
+
for( i = 0; i < roi.height; i++ )
|
248
|
+
{
|
249
|
+
const uchar* src = (const uchar*)(_src.data + _src.step*i);
|
250
|
+
uchar* dst = (uchar*)(_dst.data + _dst.step*i);
|
251
|
+
|
252
|
+
for( j = j_scalar; j <= roi.width - 4; j += 4 )
|
253
|
+
{
|
254
|
+
uchar t0 = tab[src[j]];
|
255
|
+
uchar t1 = tab[src[j+1]];
|
256
|
+
|
257
|
+
dst[j] = t0;
|
258
|
+
dst[j+1] = t1;
|
259
|
+
|
260
|
+
t0 = tab[src[j+2]];
|
261
|
+
t1 = tab[src[j+3]];
|
262
|
+
|
263
|
+
dst[j+2] = t0;
|
264
|
+
dst[j+3] = t1;
|
265
|
+
}
|
266
|
+
|
267
|
+
for( ; j < roi.width; j++ )
|
268
|
+
dst[j] = tab[src[j]];
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
static void
|
275
|
+
thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
|
276
|
+
{
|
277
|
+
int i, j;
|
278
|
+
Size roi = _src.size();
|
279
|
+
roi.width *= _src.channels();
|
280
|
+
const float* src = (const float*)_src.data;
|
281
|
+
float* dst = (float*)_dst.data;
|
282
|
+
size_t src_step = _src.step/sizeof(src[0]);
|
283
|
+
size_t dst_step = _dst.step/sizeof(dst[0]);
|
284
|
+
|
285
|
+
#if CV_SSE2
|
286
|
+
volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE);
|
287
|
+
#endif
|
288
|
+
|
289
|
+
if( _src.isContinuous() && _dst.isContinuous() )
|
290
|
+
{
|
291
|
+
roi.width *= roi.height;
|
292
|
+
roi.height = 1;
|
293
|
+
}
|
294
|
+
|
295
|
+
switch( type )
|
296
|
+
{
|
297
|
+
case THRESH_BINARY:
|
298
|
+
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
|
299
|
+
{
|
300
|
+
j = 0;
|
301
|
+
#if CV_SSE2
|
302
|
+
if( useSIMD )
|
303
|
+
{
|
304
|
+
__m128 thresh4 = _mm_set1_ps(thresh), maxval4 = _mm_set1_ps(maxval);
|
305
|
+
for( ; j <= roi.width - 8; j += 8 )
|
306
|
+
{
|
307
|
+
__m128 v0, v1;
|
308
|
+
v0 = _mm_loadu_ps( src + j );
|
309
|
+
v1 = _mm_loadu_ps( src + j + 4 );
|
310
|
+
v0 = _mm_cmpgt_ps( v0, thresh4 );
|
311
|
+
v1 = _mm_cmpgt_ps( v1, thresh4 );
|
312
|
+
v0 = _mm_and_ps( v0, maxval4 );
|
313
|
+
v1 = _mm_and_ps( v1, maxval4 );
|
314
|
+
_mm_storeu_ps( dst + j, v0 );
|
315
|
+
_mm_storeu_ps( dst + j + 4, v1 );
|
316
|
+
}
|
317
|
+
}
|
318
|
+
#endif
|
319
|
+
|
320
|
+
for( ; j < roi.width; j++ )
|
321
|
+
dst[j] = src[j] > thresh ? maxval : 0;
|
322
|
+
}
|
323
|
+
break;
|
324
|
+
|
325
|
+
case THRESH_BINARY_INV:
|
326
|
+
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
|
327
|
+
{
|
328
|
+
j = 0;
|
329
|
+
#if CV_SSE2
|
330
|
+
if( useSIMD )
|
331
|
+
{
|
332
|
+
__m128 thresh4 = _mm_set1_ps(thresh), maxval4 = _mm_set1_ps(maxval);
|
333
|
+
for( ; j <= roi.width - 8; j += 8 )
|
334
|
+
{
|
335
|
+
__m128 v0, v1;
|
336
|
+
v0 = _mm_loadu_ps( src + j );
|
337
|
+
v1 = _mm_loadu_ps( src + j + 4 );
|
338
|
+
v0 = _mm_cmple_ps( v0, thresh4 );
|
339
|
+
v1 = _mm_cmple_ps( v1, thresh4 );
|
340
|
+
v0 = _mm_and_ps( v0, maxval4 );
|
341
|
+
v1 = _mm_and_ps( v1, maxval4 );
|
342
|
+
_mm_storeu_ps( dst + j, v0 );
|
343
|
+
_mm_storeu_ps( dst + j + 4, v1 );
|
344
|
+
}
|
345
|
+
}
|
346
|
+
#endif
|
347
|
+
|
348
|
+
for( ; j < roi.width; j++ )
|
349
|
+
dst[j] = src[j] <= thresh ? maxval : 0;
|
350
|
+
}
|
351
|
+
break;
|
352
|
+
|
353
|
+
case THRESH_TRUNC:
|
354
|
+
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
|
355
|
+
{
|
356
|
+
j = 0;
|
357
|
+
#if CV_SSE2
|
358
|
+
if( useSIMD )
|
359
|
+
{
|
360
|
+
__m128 thresh4 = _mm_set1_ps(thresh);
|
361
|
+
for( ; j <= roi.width - 8; j += 8 )
|
362
|
+
{
|
363
|
+
__m128 v0, v1;
|
364
|
+
v0 = _mm_loadu_ps( src + j );
|
365
|
+
v1 = _mm_loadu_ps( src + j + 4 );
|
366
|
+
v0 = _mm_min_ps( v0, thresh4 );
|
367
|
+
v1 = _mm_min_ps( v1, thresh4 );
|
368
|
+
_mm_storeu_ps( dst + j, v0 );
|
369
|
+
_mm_storeu_ps( dst + j + 4, v1 );
|
370
|
+
}
|
371
|
+
}
|
372
|
+
#endif
|
373
|
+
|
374
|
+
for( ; j < roi.width; j++ )
|
375
|
+
dst[j] = std::min(src[j], thresh);
|
376
|
+
}
|
377
|
+
break;
|
378
|
+
|
379
|
+
case THRESH_TOZERO:
|
380
|
+
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
|
381
|
+
{
|
382
|
+
j = 0;
|
383
|
+
#if CV_SSE2
|
384
|
+
if( useSIMD )
|
385
|
+
{
|
386
|
+
__m128 thresh4 = _mm_set1_ps(thresh);
|
387
|
+
for( ; j <= roi.width - 8; j += 8 )
|
388
|
+
{
|
389
|
+
__m128 v0, v1;
|
390
|
+
v0 = _mm_loadu_ps( src + j );
|
391
|
+
v1 = _mm_loadu_ps( src + j + 4 );
|
392
|
+
v0 = _mm_and_ps(v0, _mm_cmpgt_ps(v0, thresh4));
|
393
|
+
v1 = _mm_and_ps(v1, _mm_cmpgt_ps(v1, thresh4));
|
394
|
+
_mm_storeu_ps( dst + j, v0 );
|
395
|
+
_mm_storeu_ps( dst + j + 4, v1 );
|
396
|
+
}
|
397
|
+
}
|
398
|
+
#endif
|
399
|
+
|
400
|
+
for( ; j < roi.width; j++ )
|
401
|
+
{
|
402
|
+
float v = src[j];
|
403
|
+
dst[j] = v > thresh ? v : 0;
|
404
|
+
}
|
405
|
+
}
|
406
|
+
break;
|
407
|
+
|
408
|
+
case THRESH_TOZERO_INV:
|
409
|
+
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
|
410
|
+
{
|
411
|
+
j = 0;
|
412
|
+
#if CV_SSE2
|
413
|
+
if( useSIMD )
|
414
|
+
{
|
415
|
+
__m128 thresh4 = _mm_set1_ps(thresh);
|
416
|
+
for( ; j <= roi.width - 8; j += 8 )
|
417
|
+
{
|
418
|
+
__m128 v0, v1;
|
419
|
+
v0 = _mm_loadu_ps( src + j );
|
420
|
+
v1 = _mm_loadu_ps( src + j + 4 );
|
421
|
+
v0 = _mm_and_ps(v0, _mm_cmple_ps(v0, thresh4));
|
422
|
+
v1 = _mm_and_ps(v1, _mm_cmple_ps(v1, thresh4));
|
423
|
+
_mm_storeu_ps( dst + j, v0 );
|
424
|
+
_mm_storeu_ps( dst + j + 4, v1 );
|
425
|
+
}
|
426
|
+
}
|
427
|
+
#endif
|
428
|
+
for( ; j < roi.width; j++ )
|
429
|
+
{
|
430
|
+
float v = src[j];
|
431
|
+
dst[j] = v <= thresh ? v : 0;
|
432
|
+
}
|
433
|
+
}
|
434
|
+
break;
|
435
|
+
default:
|
436
|
+
return CV_Error( CV_StsBadArg, "" );
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
|
441
|
+
static double
|
442
|
+
getThreshVal_Otsu_8u( const Mat& _src )
|
443
|
+
{
|
444
|
+
Size size = _src.size();
|
445
|
+
if( _src.isContinuous() )
|
446
|
+
{
|
447
|
+
size.width *= size.height;
|
448
|
+
size.height = 1;
|
449
|
+
}
|
450
|
+
const int N = 256;
|
451
|
+
int i, j, h[N] = {0};
|
452
|
+
for( i = 0; i < size.height; i++ )
|
453
|
+
{
|
454
|
+
const uchar* src = _src.data + _src.step*i;
|
455
|
+
for( j = 0; j <= size.width - 4; j += 4 )
|
456
|
+
{
|
457
|
+
int v0 = src[j], v1 = src[j+1];
|
458
|
+
h[v0]++; h[v1]++;
|
459
|
+
v0 = src[j+2]; v1 = src[j+3];
|
460
|
+
h[v0]++; h[v1]++;
|
461
|
+
}
|
462
|
+
for( ; j < size.width; j++ )
|
463
|
+
h[src[j]]++;
|
464
|
+
}
|
465
|
+
|
466
|
+
double mu = 0, scale = 1./(size.width*size.height);
|
467
|
+
for( i = 0; i < N; i++ )
|
468
|
+
mu += i*(double)h[i];
|
469
|
+
|
470
|
+
mu *= scale;
|
471
|
+
double mu1 = 0, q1 = 0;
|
472
|
+
double max_sigma = 0, max_val = 0;
|
473
|
+
|
474
|
+
for( i = 0; i < N; i++ )
|
475
|
+
{
|
476
|
+
double p_i, q2, mu2, sigma;
|
477
|
+
|
478
|
+
p_i = h[i]*scale;
|
479
|
+
mu1 *= q1;
|
480
|
+
q1 += p_i;
|
481
|
+
q2 = 1. - q1;
|
482
|
+
|
483
|
+
if( std::min(q1,q2) < FLT_EPSILON || std::max(q1,q2) > 1. - FLT_EPSILON )
|
484
|
+
continue;
|
485
|
+
|
486
|
+
mu1 = (mu1 + i*p_i)/q1;
|
487
|
+
mu2 = (mu - q1*mu1)/q2;
|
488
|
+
sigma = q1*q2*(mu1 - mu2)*(mu1 - mu2);
|
489
|
+
if( sigma > max_sigma )
|
490
|
+
{
|
491
|
+
max_sigma = sigma;
|
492
|
+
max_val = i;
|
493
|
+
}
|
494
|
+
}
|
495
|
+
|
496
|
+
return max_val;
|
497
|
+
}
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type )
|
502
|
+
{
|
503
|
+
Mat src = _src.getMat();
|
504
|
+
bool use_otsu = (type & THRESH_OTSU) != 0;
|
505
|
+
type &= THRESH_MASK;
|
506
|
+
|
507
|
+
if( use_otsu )
|
508
|
+
{
|
509
|
+
CV_Assert( src.type() == CV_8UC1 );
|
510
|
+
thresh = getThreshVal_Otsu_8u(src);
|
511
|
+
}
|
512
|
+
|
513
|
+
_dst.create( src.size(), src.type() );
|
514
|
+
Mat dst = _dst.getMat();
|
515
|
+
|
516
|
+
if( src.depth() == CV_8U )
|
517
|
+
{
|
518
|
+
int ithresh = cvFloor(thresh);
|
519
|
+
thresh = ithresh;
|
520
|
+
int imaxval = cvRound(maxval);
|
521
|
+
if( type == THRESH_TRUNC )
|
522
|
+
imaxval = ithresh;
|
523
|
+
imaxval = saturate_cast<uchar>(imaxval);
|
524
|
+
|
525
|
+
if( ithresh < 0 || ithresh >= 255 )
|
526
|
+
{
|
527
|
+
if( type == THRESH_BINARY || type == THRESH_BINARY_INV ||
|
528
|
+
((type == THRESH_TRUNC || type == THRESH_TOZERO_INV) && ithresh < 0) ||
|
529
|
+
(type == THRESH_TOZERO && ithresh >= 255) )
|
530
|
+
{
|
531
|
+
int v = type == THRESH_BINARY ? (ithresh >= 255 ? 0 : imaxval) :
|
532
|
+
type == THRESH_BINARY_INV ? (ithresh >= 255 ? imaxval : 0) :
|
533
|
+
type == THRESH_TRUNC ? imaxval : 0;
|
534
|
+
dst.setTo(v);
|
535
|
+
}
|
536
|
+
else
|
537
|
+
src.copyTo(dst);
|
538
|
+
}
|
539
|
+
else
|
540
|
+
thresh_8u( src, dst, (uchar)ithresh, (uchar)imaxval, type );
|
541
|
+
}
|
542
|
+
else if( src.depth() == CV_32F )
|
543
|
+
thresh_32f( src, dst, (float)thresh, (float)maxval, type );
|
544
|
+
else
|
545
|
+
CV_Error( CV_StsUnsupportedFormat, "" );
|
546
|
+
|
547
|
+
return thresh;
|
548
|
+
}
|
549
|
+
|
550
|
+
|
551
|
+
void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
|
552
|
+
int method, int type, int blockSize, double delta )
|
553
|
+
{
|
554
|
+
Mat src = _src.getMat();
|
555
|
+
CV_Assert( src.type() == CV_8UC1 );
|
556
|
+
CV_Assert( blockSize % 2 == 1 && blockSize > 1 );
|
557
|
+
Size size = src.size();
|
558
|
+
|
559
|
+
_dst.create( size, src.type() );
|
560
|
+
Mat dst = _dst.getMat();
|
561
|
+
|
562
|
+
if( maxValue < 0 )
|
563
|
+
{
|
564
|
+
dst = Scalar(0);
|
565
|
+
return;
|
566
|
+
}
|
567
|
+
|
568
|
+
Mat mean;
|
569
|
+
|
570
|
+
if( src.data != dst.data )
|
571
|
+
mean = dst;
|
572
|
+
|
573
|
+
if( method == ADAPTIVE_THRESH_MEAN_C )
|
574
|
+
boxFilter( src, mean, src.type(), Size(blockSize, blockSize),
|
575
|
+
Point(-1,-1), true, BORDER_REPLICATE );
|
576
|
+
else if( method == ADAPTIVE_THRESH_GAUSSIAN_C )
|
577
|
+
GaussianBlur( src, mean, Size(blockSize, blockSize), 0, 0, BORDER_REPLICATE );
|
578
|
+
else
|
579
|
+
CV_Error( CV_StsBadFlag, "Unknown/unsupported adaptive threshold method" );
|
580
|
+
|
581
|
+
int i, j;
|
582
|
+
uchar imaxval = saturate_cast<uchar>(maxValue);
|
583
|
+
int idelta = type == THRESH_BINARY ? cvCeil(delta) : cvFloor(delta);
|
584
|
+
uchar tab[768];
|
585
|
+
|
586
|
+
if( type == CV_THRESH_BINARY )
|
587
|
+
for( i = 0; i < 768; i++ )
|
588
|
+
tab[i] = (uchar)(i - 255 > -idelta ? imaxval : 0);
|
589
|
+
else if( type == CV_THRESH_BINARY_INV )
|
590
|
+
for( i = 0; i < 768; i++ )
|
591
|
+
tab[i] = (uchar)(i - 255 <= -idelta ? imaxval : 0);
|
592
|
+
else
|
593
|
+
CV_Error( CV_StsBadFlag, "Unknown/unsupported threshold type" );
|
594
|
+
|
595
|
+
if( src.isContinuous() && mean.isContinuous() && dst.isContinuous() )
|
596
|
+
{
|
597
|
+
size.width *= size.height;
|
598
|
+
size.height = 1;
|
599
|
+
}
|
600
|
+
|
601
|
+
for( i = 0; i < size.height; i++ )
|
602
|
+
{
|
603
|
+
const uchar* sdata = src.data + src.step*i;
|
604
|
+
const uchar* mdata = mean.data + mean.step*i;
|
605
|
+
uchar* ddata = dst.data + dst.step*i;
|
606
|
+
|
607
|
+
for( j = 0; j < size.width; j++ )
|
608
|
+
ddata[j] = tab[sdata[j] - mdata[j] + 255];
|
609
|
+
}
|
610
|
+
}
|
611
|
+
|
612
|
+
CV_IMPL double
|
613
|
+
cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, int type )
|
614
|
+
{
|
615
|
+
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr), dst0 = dst;
|
616
|
+
|
617
|
+
CV_Assert( src.size == dst.size && src.channels() == dst.channels() &&
|
618
|
+
(src.depth() == dst.depth() || dst.depth() == CV_8U));
|
619
|
+
|
620
|
+
thresh = cv::threshold( src, dst, thresh, maxval, type );
|
621
|
+
if( dst0.data != dst.data )
|
622
|
+
dst.convertTo( dst0, dst0.depth() );
|
623
|
+
return thresh;
|
624
|
+
}
|
625
|
+
|
626
|
+
|
627
|
+
CV_IMPL void
|
628
|
+
cvAdaptiveThreshold( const void *srcIm, void *dstIm, double maxValue,
|
629
|
+
int method, int type, int blockSize, double delta )
|
630
|
+
{
|
631
|
+
cv::Mat src = cv::cvarrToMat(srcIm), dst = cv::cvarrToMat(dstIm);
|
632
|
+
CV_Assert( src.size == dst.size && src.type() == dst.type() );
|
633
|
+
cv::adaptiveThreshold( src, dst, maxValue, method, type, blockSize, delta );
|
634
|
+
}
|
635
|
+
|
636
|
+
/* End of file. */
|