MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ harris_response() [1/2]

MAYAFLUX_API void MayaFlux::Kinesis::Vision::harris_response ( std::span< const float >  gray,
std::span< float >  dx,
std::span< float >  dy,
std::span< float >  tmp,
std::span< float >  ixx,
std::span< float >  iyy,
std::span< float >  ixy,
std::span< float >  sxx,
std::span< float >  syy,
std::span< float >  sxy,
std::span< float >  dst,
uint32_t  w,
uint32_t  h,
float  k,
std::span< const float >  kern 
)

Compute the Harris corner response map into caller-supplied buffers.

Writes the normalised response into dst. Intermediate buffers dx/dy/tmp/ixx/iyy/ixy/sxx/syy/sxy must each be size >= w * h and must not alias each other or gray.

Parameters
graySingle-channel float span, size w * h.
dxScratch: horizontal gradient, size >= w * h.
dyScratch: vertical gradient, size >= w * h.
tmpScratch: filter horizontal pass, size >= w * h.
ixxScratch: structure tensor Ixx, size >= w * h.
iyyScratch: structure tensor Iyy, size >= w * h.
ixyScratch: structure tensor Ixy, size >= w * h.
sxxScratch: smoothed Sxx, size >= w * h.
syyScratch: smoothed Syy, size >= w * h.
sxyScratch: smoothed Sxy, size >= w * h.
dstOutput response map, size >= w * h, values in [0, 1].
wImage width in pixels.
hImage height in pixels.
kHarris sensitivity parameter. Typical range [0.04, 0.06].
kernPrecomputed 1D Gaussian kernel for structure tensor smoothing.

Definition at line 77 of file Harris.cpp.

86{
87 const size_t n = static_cast<size_t>(w) * h;
88
89 sobel(gray, dx, dy, tmp, w, h);
90
91 {
92 const float* dx_ptr = dx.data();
93 const float* dy_ptr = dy.data();
94 float* ixx_ptr = ixx.data();
95 float* iyy_ptr = iyy.data();
96 float* ixy_ptr = ixy.data();
97
98 std::for_each(std::execution::par_unseq,
99 std::views::iota(size_t { 0 }, n).begin(),
100 std::views::iota(size_t { 0 }, n).end(),
101 [&](size_t i) {
102 const float gx = dx_ptr[i];
103 const float gy = dy_ptr[i];
104 ixx_ptr[i] = gx * gx;
105 iyy_ptr[i] = gy * gy;
106 ixy_ptr[i] = gx * gy;
107 });
108 }
109
110 const float* h_src[3] = { ixx.data(), iyy.data(), ixy.data() };
111 float* h_dst[3] = { dx.data(), dy.data(), tmp.data() };
112 filter_horizontal_planes({ h_src, 3 }, { h_dst, 3 }, w, h, kern);
113
114 const float* v_src[3] = { dx.data(), dy.data(), tmp.data() };
115 float* v_dst[3] = { sxx.data(), syy.data(), sxy.data() };
116 filter_vertical_planes({ v_src, 3 }, { v_dst, 3 }, w, h, kern);
117
118 {
119 const float* sxx_ptr = sxx.data();
120 const float* syy_ptr = syy.data();
121 const float* sxy_ptr = sxy.data();
122 float* dst_ptr = dst.data();
123
124#ifdef MAYAFLUX_ARCH_X64
125 const __m256 k_vec = _mm256_set1_ps(k);
126 const __m256 zero = _mm256_setzero_ps();
127
128 size_t i = 0;
129 for (; i + 8 <= n; i += 8) {
130 const __m256 s0 = _mm256_loadu_ps(sxx_ptr + i);
131 const __m256 s1 = _mm256_loadu_ps(syy_ptr + i);
132 const __m256 s01 = _mm256_loadu_ps(sxy_ptr + i);
133
134 const __m256 det = _mm256_sub_ps(
135 _mm256_mul_ps(s0, s1),
136 _mm256_mul_ps(s01, s01));
137 const __m256 trace = _mm256_add_ps(s0, s1);
138 const __m256 resp = _mm256_max_ps(zero,
139 _mm256_fnmadd_ps(k_vec,
140 _mm256_mul_ps(trace, trace),
141 det));
142
143 _mm256_storeu_ps(dst_ptr + i, resp);
144 }
145 for (; i < n; ++i) {
146 const float s0 = sxx_ptr[i];
147 const float s1 = syy_ptr[i];
148 const float s01 = sxy_ptr[i];
149 const float det = s0 * s1 - s01 * s01;
150 const float trace = s0 + s1;
151 dst_ptr[i] = std::max(0.0F, det - k * trace * trace);
152 }
153
154#elif defined(MAYAFLUX_ARCH_ARM64)
155 const float32x4_t k_vec = vdupq_n_f32(k);
156 const float32x4_t zero = vdupq_n_f32(0.0F);
157
158 size_t i = 0;
159 for (; i + 4 <= n; i += 4) {
160 const float32x4_t s0 = vld1q_f32(sxx_ptr + i);
161 const float32x4_t s1 = vld1q_f32(syy_ptr + i);
162 const float32x4_t s01 = vld1q_f32(sxy_ptr + i);
163
164 const float32x4_t det = vsubq_f32(
165 vmulq_f32(s0, s1),
166 vmulq_f32(s01, s01));
167 const float32x4_t trace = vaddq_f32(s0, s1);
168 const float32x4_t resp = vmaxq_f32(zero,
169 vmlsq_f32(det, k_vec, vmulq_f32(trace, trace)));
170
171 vst1q_f32(dst_ptr + i, resp);
172 }
173 for (; i < n; ++i) {
174 const float s0 = sxx_ptr[i];
175 const float s1 = syy_ptr[i];
176 const float s01 = sxy_ptr[i];
177 const float det = s0 * s1 - s01 * s01;
178 const float trace = s0 + s1;
179 dst_ptr[i] = std::max(0.0F, det - k * trace * trace);
180 }
181
182#else
183 for (size_t i = 0; i < n; ++i) {
184 const float s0 = sxx_ptr[i];
185 const float s1 = syy_ptr[i];
186 const float s01 = sxy_ptr[i];
187 const float det = s0 * s1 - s01 * s01;
188 const float trace = s0 + s1;
189 dst_ptr[i] = std::max(0.0F, det - k * trace * trace);
190 }
191#endif
192 }
193
194 normalize_response(dst.first(n));
195}
uint32_t h
Definition InkPress.cpp:29
uint32_t * dst
void sobel(std::span< const float > gray, std::span< float > dx, std::span< float > dy, std::span< float > tmp, uint32_t w, uint32_t h)
Sobel gradient writing dx and dy into caller-supplied buffers.
Definition Gradient.cpp:64
void filter_horizontal_planes(std::span< const float *const > src, std::span< float *const > dst, uint32_t w, uint32_t h, std::span< const float > kernel)
Fused horizontal separable filter over N planes.
void filter_vertical_planes(std::span< const float *const > src, std::span< float *const > dst, uint32_t w, uint32_t h, std::span< const float > kernel)
Fused vertical separable filter over N planes.

References dst, filter_horizontal_planes(), filter_vertical_planes(), h, and sobel().

+ Here is the call graph for this function: