MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / InitIndices

Function InitIndices

jni/stasm/hat.cpp:80–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78// for this pixel are irow=-1 row_frac=0.5.
79
80static inline void InitIndices(
81 vec_int& row_indices, // out
82 vec_double& row_fracs, // out
83 vec_int& col_indices, // out
84 vec_double& col_fracs, // out
85 vec_double& pixelweights, // out
86 const int patchwidth) // in: in pixels
87{
88 CV_Assert(patchwidth % 2 == 1); // patchwidth must be odd in this implementation
89
90 const int npix = SQ(patchwidth); // number of pixels in image patch
91
92 row_indices.resize(npix);
93 row_fracs.resize(npix);
94 col_indices.resize(npix);
95 col_fracs.resize(npix);
96 pixelweights.resize(npix);
97
98 const int halfpatchwidth = (patchwidth-1) / 2;
99
100 const double grid_rows_per_img_row = GRIDHEIGHT / (patchwidth-1.);
101 const double row_offset = GRIDHEIGHT / 2. - .5; // see header comment
102
103 const double grid_cols_per_img_col = GRIDWIDTH / (patchwidth-1.);
104 const double col_offset = GRIDWIDTH / 2. - .5;
105
106 // downweight at border of patch is exp(-1 / (2 * WINDOW_SIGMA))
107 const double weight = -1 / (WINDOW_SIGMA * GRIDHEIGHT * GRIDWIDTH );
108
109 int ipix = 0;
110
111 for (double patchrow = -halfpatchwidth; patchrow <= halfpatchwidth; patchrow++)
112 {
113 const double signed_row = patchrow * grid_rows_per_img_row;
114 const double row = signed_row + row_offset;
115 const int irow = int(floor(row));
116 const double row_frac = row - irow;
117
118 CV_DbgAssert(row >= -.5 && row <= GRIDHEIGHT - .5); // same applies to col below
119
120 for (double patchcol = -halfpatchwidth; patchcol <= halfpatchwidth; patchcol++)
121 {
122 row_indices[ipix] = irow;
123 row_fracs[ipix] = row_frac;
124
125 const double signed_col = patchcol * grid_cols_per_img_col;
126 const double col = signed_col + col_offset;
127 const int icol = int(floor(col));
128
129 col_indices[ipix] = icol;
130 col_fracs[ipix] = col - icol;
131
132 pixelweights[ipix] = // TODO this weights col and row offsets equally
133 exp(weight * (SQ(signed_row) + SQ(signed_col)));
134
135 ipix++;
136 }
137 }

Callers 1

Init_Method · 0.85

Calls 1

SQFunction · 0.85

Tested by

no test coverage detected