MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / ComputeDerivatives

Function ComputeDerivatives

cpp/5_Domain_Specific/HSOpticalFlow/flowGold.cpp:225–267  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// \brief computes image derivatives for a pair of images \param[in] I0 source image \param[in] I1 tracked image \param[in] w images width \param[in] h images height \param[in] s images stride \param[out] Ix x derivative \param[out] Iy y derivative \param[out] Iz temporal derivative ////////////////////////////

Source from the content-addressed store, hash-verified

223/// \param[out] Iz temporal derivative
224///////////////////////////////////////////////////////////////////////////////
225static void ComputeDerivatives(const float *I0, const float *I1, int w, int h, int s, float *Ix, float *Iy, float *Iz)
226{
227 for (int i = 0; i < h; ++i) {
228 for (int j = 0; j < w; ++j) {
229 const int pos = j + i * s;
230 float t0, t1;
231 // derivative filter is (1, -8, 0, 8, -1)/12
232 // x derivative
233 t0 = Tex2Di(I0, w, h, s, j - 2, i);
234 t0 -= Tex2Di(I0, w, h, s, j - 1, i) * 8.0f;
235 t0 += Tex2Di(I0, w, h, s, j + 1, i) * 8.0f;
236 t0 -= Tex2Di(I0, w, h, s, j + 2, i);
237 t0 /= 12.0f;
238
239 t1 = Tex2Di(I1, w, h, s, j - 2, i);
240 t1 -= Tex2Di(I1, w, h, s, j - 1, i) * 8.0f;
241 t1 += Tex2Di(I1, w, h, s, j + 1, i) * 8.0f;
242 t1 -= Tex2Di(I1, w, h, s, j + 2, i);
243 t1 /= 12.0f;
244
245 // spatial derivatives are averaged
246 Ix[pos] = (t0 + t1) * 0.5f;
247
248 // t derivative
249 Iz[pos] = I1[pos] - I0[pos];
250
251 // y derivative
252 t0 = Tex2Di(I0, w, h, s, j, i - 2);
253 t0 -= Tex2Di(I0, w, h, s, j, i - 1) * 8.0f;
254 t0 += Tex2Di(I0, w, h, s, j, i + 1) * 8.0f;
255 t0 -= Tex2Di(I0, w, h, s, j, i + 2);
256 t0 /= 12.0f;
257
258 t1 = Tex2Di(I1, w, h, s, j, i - 2);
259 t1 -= Tex2Di(I1, w, h, s, j, i - 1) * 8.0f;
260 t1 += Tex2Di(I1, w, h, s, j, i + 1) * 8.0f;
261 t1 -= Tex2Di(I1, w, h, s, j, i + 2);
262 t1 /= 12.0f;
263
264 Iy[pos] = (t0 + t1) * 0.5f;
265 }
266 }
267}
268
269///////////////////////////////////////////////////////////////////////////////
270/// \brief one iteration of classical Horn-Schunck method

Callers 1

ComputeFlowGoldFunction · 0.85

Calls 1

Tex2DiFunction · 0.85

Tested by

no test coverage detected