inline __host__ __device__ i_short2 gradient_descent_match2(i_short2 prediction, F f, FI& feature_img, float& distance, unsigned scale = 1) { i_short2 match = prediction; float match_distance = feature_img.distance(f, prediction); unsigned match_i = 8; box2d domain = feature_img.domain() - border(7); if (!domain.has(prediction)) return prediction; assert(domain.has(prediction)); for (int search = 0; search < 7; search++) { for(int i = 0; i != 25; i++) { i_int2 n(prediction + i_int2(c25_h[i])); { float d = feature_img.distance(f, n, scale); if (d < match_distance) { match = n; match_i = i; match_distance = d; } } } if (i_int2(prediction) == i_int2(match) || !domain.has(match)) break; else prediction = match; } distance = match_distance; return match; }
inline __host__ __device__ std::pair<i_short2, float> gradient_descent_match(i_short2 prediction_, F f, FI& feature_img, unsigned scale = 1) { typedef std::pair<i_short2, float> ret; i_short2 prediction = prediction_; typedef typename FI::architecture A; i_short2 match = prediction; float match_distance = feature_img.distance(f, prediction); unsigned match_i = 8; box2d domain = feature_img.domain() - border(0); if (!domain.has(prediction)) { return ret(prediction, 999999.f); } assert(domain.has(prediction)); for (int search = 0; search < 10; search++) { int i = arch_neighb2d<A>::get(c8_it_h, c8_it, match_i)[0]; int end = arch_neighb2d<A>::get(c8_it_h, c8_it, match_i)[1]; { i_int2 n(prediction + i_int2(arch_neighb2d<A>::get(c8_h, c8, i))); if (feature_img.domain().has(n)) { float d = feature_img.distance(f, n, scale); if (d < match_distance) { match = n; match_i = i; match_distance = d; } } i = (i + 1) & 7; } #pragma unroll 4 for(; i != end; i = (i + 1) & 7) { i_int2 n(prediction + i_int2(arch_neighb2d<A>::get(c8_h, c8, i))); if (feature_img.domain().has(n)) { float d = feature_img.distance(f, n, scale); if (d < match_distance) { match = n; match_i = i; match_distance = d; } } } if (i_int2(prediction) == i_int2(match) || !domain.has(match)) break; else prediction = match; } // if (scale == 2) // match = prediction + 2 * (match - prediction); // match_distance = feature_img.distance(f, match, scale); return ret(match, match_distance); }