@@ -123,7 +123,7 @@ static inline int getGaussianKernelSize(float sigma) {
123
123
* dL_by_ds = d(c dL_by_dx)_by_dx + d(c dL_by_dy)_by_dy
124
124
*/
125
125
static inline void
126
- nld_step_scalar_one_lane (const Mat& Lt, const Mat& Lf, Mat& Lstep, int row_begin, int row_end)
126
+ nld_step_scalar_one_lane (const Mat& Lt, const Mat& Lf, Mat& Lstep, float step_size, int row_begin, int row_end)
127
127
{
128
128
CV_INSTRUMENT_REGION ()
129
129
/* The labeling scheme for this five star stencil:
@@ -139,6 +139,7 @@ nld_step_scalar_one_lane(const Mat& Lt, const Mat& Lf, Mat& Lstep, int row_begin
139
139
const float *lt_a, *lt_c, *lt_b;
140
140
const float *lf_a, *lf_c, *lf_b;
141
141
float *dst;
142
+ float step_r = 0 .f ;
142
143
143
144
// Process the top row
144
145
if (row == 0 ) {
@@ -149,9 +150,10 @@ nld_step_scalar_one_lane(const Mat& Lt, const Mat& Lf, Mat& Lstep, int row_begin
149
150
dst = Lstep.ptr <float >(0 ) + 1 ;
150
151
151
152
for (int j = 0 ; j < cols; j++) {
152
- dst[j] = (lf_c[j] + lf_c[j + 1 ])*(lt_c[j + 1 ] - lt_c[j]) +
153
- (lf_c[j] + lf_c[j - 1 ])*(lt_c[j - 1 ] - lt_c[j]) +
154
- (lf_c[j] + lf_b[j ])*(lt_b[j ] - lt_c[j]);
153
+ step_r = (lf_c[j] + lf_c[j + 1 ])*(lt_c[j + 1 ] - lt_c[j]) +
154
+ (lf_c[j] + lf_c[j - 1 ])*(lt_c[j - 1 ] - lt_c[j]) +
155
+ (lf_c[j] + lf_b[j ])*(lt_b[j ] - lt_c[j]);
156
+ dst[j] = step_r * step_size;
155
157
}
156
158
++row;
157
159
}
@@ -169,9 +171,10 @@ nld_step_scalar_one_lane(const Mat& Lt, const Mat& Lf, Mat& Lstep, int row_begin
169
171
dst = Lstep.ptr <float >(row);
170
172
171
173
// The left-most column
172
- dst[ 0 ] = (lf_c[0 ] + lf_c[1 ])*(lt_c[1 ] - lt_c[0 ]) +
174
+ step_r = (lf_c[0 ] + lf_c[1 ])*(lt_c[1 ] - lt_c[0 ]) +
173
175
(lf_c[0 ] + lf_b[0 ])*(lt_b[0 ] - lt_c[0 ]) +
174
176
(lf_c[0 ] + lf_a[0 ])*(lt_a[0 ] - lt_c[0 ]);
177
+ dst[0 ] = step_r * step_size;
175
178
176
179
lt_a++; lt_c++; lt_b++;
177
180
lf_a++; lf_c++; lf_b++;
@@ -180,16 +183,18 @@ nld_step_scalar_one_lane(const Mat& Lt, const Mat& Lf, Mat& Lstep, int row_begin
180
183
// The middle columns
181
184
for (int j = 0 ; j < cols; j++)
182
185
{
183
- dst[j] = (lf_c[j] + lf_c[j + 1 ])*(lt_c[j + 1 ] - lt_c[j]) +
186
+ step_r = (lf_c[j] + lf_c[j + 1 ])*(lt_c[j + 1 ] - lt_c[j]) +
184
187
(lf_c[j] + lf_c[j - 1 ])*(lt_c[j - 1 ] - lt_c[j]) +
185
188
(lf_c[j] + lf_b[j ])*(lt_b[j ] - lt_c[j]) +
186
189
(lf_c[j] + lf_a[j ])*(lt_a[j ] - lt_c[j]);
190
+ dst[j] = step_r * step_size;
187
191
}
188
192
189
193
// The right-most column
190
- dst[cols] = (lf_c[cols] + lf_c[cols - 1 ])*(lt_c[cols - 1 ] - lt_c[cols]) +
191
- (lf_c[cols] + lf_b[cols ])*(lt_b[cols ] - lt_c[cols]) +
192
- (lf_c[cols] + lf_a[cols ])*(lt_a[cols ] - lt_c[cols]);
194
+ step_r = (lf_c[cols] + lf_c[cols - 1 ])*(lt_c[cols - 1 ] - lt_c[cols]) +
195
+ (lf_c[cols] + lf_b[cols ])*(lt_b[cols ] - lt_c[cols]) +
196
+ (lf_c[cols] + lf_a[cols ])*(lt_a[cols ] - lt_c[cols]);
197
+ dst[cols] = step_r * step_size;
193
198
}
194
199
195
200
// Process the bottom row (row == Lt.rows - 1)
@@ -201,29 +206,31 @@ nld_step_scalar_one_lane(const Mat& Lt, const Mat& Lf, Mat& Lstep, int row_begin
201
206
dst = Lstep.ptr <float >(row) +1 ;
202
207
203
208
for (int j = 0 ; j < cols; j++) {
204
- dst[j] = (lf_c[j] + lf_c[j + 1 ])*(lt_c[j + 1 ] - lt_c[j]) +
205
- (lf_c[j] + lf_c[j - 1 ])*(lt_c[j - 1 ] - lt_c[j]) +
206
- (lf_c[j] + lf_a[j ])*(lt_a[j ] - lt_c[j]);
209
+ step_r = (lf_c[j] + lf_c[j + 1 ])*(lt_c[j + 1 ] - lt_c[j]) +
210
+ (lf_c[j] + lf_c[j - 1 ])*(lt_c[j - 1 ] - lt_c[j]) +
211
+ (lf_c[j] + lf_a[j ])*(lt_a[j ] - lt_c[j]);
212
+ dst[j] = step_r * step_size;
207
213
}
208
214
}
209
215
}
210
216
211
217
class NonLinearScalarDiffusionStep : public ParallelLoopBody
212
218
{
213
219
public:
214
- NonLinearScalarDiffusionStep (const Mat& Lt, const Mat& Lf, Mat& Lstep)
215
- : Lt_(&Lt), Lf_(&Lf), Lstep_(&Lstep)
220
+ NonLinearScalarDiffusionStep (const Mat& Lt, const Mat& Lf, Mat& Lstep, float step_size )
221
+ : Lt_(&Lt), Lf_(&Lf), Lstep_(&Lstep), step_size_(step_size)
216
222
{}
217
223
218
224
void operator ()(const Range& range) const
219
225
{
220
- nld_step_scalar_one_lane (*Lt_, *Lf_, *Lstep_, range.start , range.end );
226
+ nld_step_scalar_one_lane (*Lt_, *Lf_, *Lstep_, step_size_, range.start , range.end );
221
227
}
222
228
223
229
private:
224
230
const Mat* Lt_;
225
231
const Mat* Lf_;
226
232
Mat* Lstep_;
233
+ float step_size_;
227
234
};
228
235
229
236
/* *
@@ -310,10 +317,9 @@ int AKAZEFeatures::Create_Nonlinear_Scale_Space(const Mat& img)
310
317
std::vector<float > &tsteps = tsteps_[i - 1 ];
311
318
for (size_t j = 0 ; j < tsteps.size (); j++) {
312
319
// Lstep must be preallocated before this parallel loop
313
- parallel_for_ (Range (0 , e.Lt .rows ), NonLinearScalarDiffusionStep (e.Lt , Lflow, Lstep),
314
- (double )e.Lt .total ()/(1 << 16 ));
315
- const float step_size = tsteps[j];
316
- e.Lt += Lstep * (0 .5f * step_size);
320
+ const float step_size = tsteps[j] * 0 .5f ;
321
+ parallel_for_ (Range (0 , e.Lt .rows ), NonLinearScalarDiffusionStep (e.Lt , Lflow, Lstep, step_size));
322
+ e.Lt += Lstep;
317
323
}
318
324
}
319
325
0 commit comments