14 static const int s_nSamplesInitPatternWidth = 7;
15 static const int s_nSamplesInitPatternHeight = 7;
16 static const int s_nSamplesInitPatternTot = 512;
17 static const int s_anSamplesInitPattern[s_nSamplesInitPatternHeight][s_nSamplesInitPatternWidth] = {
18 {2, 4, 6, 7, 6, 4, 2,},
19 {4, 8, 12, 14, 12, 8, 4,},
20 {6, 12, 21, 25, 21, 12, 6,},
21 {7, 14, 25, 28, 25, 14, 7,},
22 {6, 12, 21, 25, 21, 12, 6,},
23 {4, 8, 12, 14, 12, 8, 4,},
24 {2, 4, 6, 7, 6, 4, 2,},
28 static inline void getRandSamplePosition(
int& x_sample,
int& y_sample,
const int x_orig,
const int y_orig,
const int border,
const cv::Size& imgsize) {
29 int r = 1+rand()%s_nSamplesInitPatternTot;
30 for(x_sample=0; x_sample<s_nSamplesInitPatternWidth; ++x_sample) {
31 for(y_sample=0; y_sample<s_nSamplesInitPatternHeight; ++y_sample) {
32 r -= s_anSamplesInitPattern[y_sample][x_sample];
38 x_sample += x_orig-s_nSamplesInitPatternWidth/2;
39 y_sample += y_orig-s_nSamplesInitPatternHeight/2;
42 else if(x_sample>=imgsize.width-border)
43 x_sample = imgsize.width-border-1;
46 else if(y_sample>=imgsize.height-border)
47 y_sample = imgsize.height-border-1;
51 static const int s_anNeighborPatternSize_3x3 = 8;
52 static const int s_anNeighborPattern_3x3[8][2] = {
53 {-1, 1}, { 0, 1}, { 1, 1},
55 {-1,-1}, { 0,-1}, { 1,-1},
59 static inline void getRandNeighborPosition_3x3(
int& x_neighbor,
int& y_neighbor,
const int x_orig,
const int y_orig,
const int border,
const cv::Size& imgsize) {
60 int r = rand()%s_anNeighborPatternSize_3x3;
61 x_neighbor = x_orig+s_anNeighborPattern_3x3[r][0];
62 y_neighbor = y_orig+s_anNeighborPattern_3x3[r][1];
65 else if(x_neighbor>=imgsize.width-border)
66 x_neighbor = imgsize.width-border-1;
69 else if(y_neighbor>=imgsize.height-border)
70 y_neighbor = imgsize.height-border-1;
74 static const int s_anNeighborPatternSize_5x5 = 24;
75 static const int s_anNeighborPattern_5x5[24][2] = {
76 {-2, 2}, {-1, 2}, { 0, 2}, { 1, 2}, { 2, 2},
77 {-2, 1}, {-1, 1}, { 0, 1}, { 1, 1}, { 2, 1},
78 {-2, 0}, {-1, 0}, { 1, 0}, { 2, 0},
79 {-2,-1}, {-1,-1}, { 0,-1}, { 1,-1}, { 2,-1},
80 {-2,-2}, {-1,-2}, { 0,-2}, { 1,-2}, { 2,-2},
84 static inline void getRandNeighborPosition_5x5(
int& x_neighbor,
int& y_neighbor,
const int x_orig,
const int y_orig,
const int border,
const cv::Size& imgsize) {
85 int r = rand()%s_anNeighborPatternSize_5x5;
86 x_neighbor = x_orig+s_anNeighborPattern_5x5[r][0];
87 y_neighbor = y_orig+s_anNeighborPattern_5x5[r][1];
90 else if(x_neighbor>=imgsize.width-border)
91 x_neighbor = imgsize.width-border-1;
94 else if(y_neighbor>=imgsize.height-border)
95 y_neighbor = imgsize.height-border-1;