<p>In <a href="https://github.com/mlpack/mlpack/pull/703#discussion_r68450940">src/mlpack/methods/edge_boxes/feature_extraction_impl.hpp</a>:</p>
<pre style='color:#555'>&gt; +    dx.slice(i).col(0) = InImage.slice(i).col(1) - InImage.slice(i).col(0);
&gt; +    dx.slice(i).col(InImage.n_cols - 1) = InImage.slice(i).col(InImage.n_cols - 1)
&gt; +                                        - InImage.slice(i).col(InImage.n_cols - 2);
&gt; +
&gt; +    for (size_t j = 1; j &lt; InImage.n_cols-1; j++)
&gt; +      dx.slice(i).col(j) = 0.5 * ( InImage.slice(i).col(j+1) - InImage.slice(i).col(j) ); 
&gt; +
&gt; +    // do same for dy.
&gt; +    dy.slice(i).row(0) = InImage.slice(i).row(1) - InImage.slice(i).row(0);
&gt; +    dy.slice(i).row(InImage.n_rows - 1) = InImage.slice(i).row(InImage.n_rows - 1)
&gt; +                                        - InImage.slice(i).row(InImage.n_rows - 2);
&gt; +
&gt; +    for (size_t j = 1; j &lt; InImage.n_rows-1; j++)
&gt; +      dy.slice(i).row(j) = 0.5 * ( InImage.slice(i).row(j+1) - InImage.slice(i).row(j) );
&gt; +  }  
&gt; +
</pre>
<p>I think by usual, we would apply convolution on the matrix directly, cnn of mlpack implement convolution algo, maybe you can use it to find out the gradient.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/pull/703/files/987f0790f745314a2117a87f28a346b05a8a2a2d#r68450940">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe/AJ4bFM7oS4KIdFeJrM6ixO8LO23QvVIRks5qPDFNgaJpZM4I5X__">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFCaJhIN6CabcMi5mp_uKbW_5Jke3ks5qPDFNgaJpZM4I5X__.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/703/files/987f0790f745314a2117a87f28a346b05a8a2a2d#r68450940"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>