Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If this is specifically for 8 bit images then you really don't want floating point coefficients, especially not double precision. Also you don't want to use floats for x1, y1. You should just use integers for coordinates and you can use fixed point (i.e. integer) for the coefficients to keep all the filter arithmetic in the integer domain, e.g.</p> <pre><code>Mat myGaussianBlur(Mat src){ Mat dst(src.rows, src.cols, CV_8UC1); Mat temp(src.rows, src.cols, CV_16UC1); // &lt;&lt;&lt; int sum, x1, y1; // &lt;&lt;&lt; // coefficients of 1D gaussian kernel with sigma = 2 double coeffs[] = {0.06475879783, 0.1209853623, 0.1760326634, 0.1994711402, 0.1760326634, 0.1209853623, 0.06475879783}; int coeffs_i[7] = { 0 }; // &lt;&lt;&lt; //Normalize coeffs float coeffs_sum = 0.9230247873f; for (int i = 0; i &lt; 7; i++){ coeffs_i[i] = (int)(coeffs[i] / coeffs_sum * 256); // &lt;&lt;&lt; } // filter vertically for(int y = 0; y &lt; src.rows; y++){ for(int x = 0; x &lt; src.cols; x++){ sum = 0; // &lt;&lt;&lt; for(int i = -3; i &lt;= 3; i++){ y1 = reflect101(src.rows, y - i); sum += coeffs_i[i + 3]*src.at&lt;uchar&gt;(y1, x); // &lt;&lt;&lt; } temp.at&lt;uchar&gt;(y,x) = sum; } } // filter horizontally for(int y = 0; y &lt; src.rows; y++){ for(int x = 0; x &lt; src.cols; x++){ sum = 0; // &lt;&lt;&lt; for(int i = -3; i &lt;= 3; i++){ x1 = reflect101(src.rows, x - i); sum += coeffs_i[i + 3]*temp.at&lt;uchar&gt;(y, x1); // &lt;&lt;&lt; } dst.at&lt;uchar&gt;(y,x) = sum / (256 * 256); // &lt;&lt;&lt; } } return dst; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload