title: How to make Gaussian Blur work properly?
body: <p>I'm writing a Gaussian Blur filter with 3x3 matrix(kernel) and using <code>QImage</code> as external library. The kernel is calculated as it has to be. After kernel is initialized and calculated I bring the <code>unsigned int</code> Matrix into the program:                            </p>
  
  <pre><code>typedef std::vector&lt;std::vector&lt;unsigned int&gt; &gt; uintMatrix; // For copying pixels value
  </code></pre>
  
  <p>In the main.cpp it's initialized like:</p>
  
  <pre><code>uintMatrix tmpPxMat(image.width(); std::vector&lt;unsigned int&gt; (image.height(), 0));
  </code></pre>
  
  <p>I use it as a temporary storage for blurred pixels values.</p>
  
  <p>Then,  I use my algorithm to blur the image:</p>
  
  <pre><code>// Blur Pixels
  for(int x = 0; x &lt; image.width(); x++)
      for(int y = 0; y &lt; image.height(); y++) {
          // To avoid edge cases don't process them, I'll fix it soon
          if(x == 0 || x == image.height()-1 || y == 0 || y == image.width()-1)
              continue;
          // 3x3 Matrix
          tmpPxMat[x][y] += kernel[0][0] * image.pixel(x-1, y-1) +
                            kernel[0][1] * image.pixel(x, y-1) +
                            kernel[0][2] * image.pixel(x+1, y-1);
  
          tmpPxMat[x][y] += kernel[1][0] * image.pixel(x-1, y) +
                            kernel[1][1] * image.pixel(x, y) +
                            kernel[1][2] * image.pixel(x+1, y);
  
          tmpPxMat[x][y] += kernel[2][0] * image.pixel(x-1, y+1) +
                            kernel[2][1] * image.pixel(x, y+1) +
                            kernel[2][2] * image.pixel(x+1, y+1);
      }
  </code></pre>
  
  <p>Then, I copy the result of <code>tmpPxMat[][]</code> to the origin image:</p>
  
  <pre><code>// Copy blurred values to the image
  for(int x = 0; x &lt; image.width(); x++)
          for(int y = 0; y &lt; image.height(); y++)
              image.setPixel(x, y, tmpPxMat[x][y]);
  </code></pre>
  
  <p>And save it:</p>
  
  <pre><code>image.save("/home/john/Pictures/blurred", "PNG", 100);
  </code></pre>
  
  <p>But at the end I get not the result I was waiting for. Here what I get:</p>
  
  <p><strong>Before / After:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/h6rZw.jpg" alt="Origin/Blurred"></p>
  
  <p>Sorry for the long question description, but I compressed it as much as I could.</p>