title: Faster Image Processing than Lock Bits
body: <p>I've been working on an edge detection program in C#, and to make it run faster, I recently made it use lock bits. However, lockBits is still not as fast as I would like it to run. Although the problem could be my general algorithm, I'm also wondering if there is anything better than lockBits I can use for image processing.</p>
  
  <p>In case the problem is the algorithm, here's a basic explanation. Go through an array of Colors (made using lockbits, which represent pixels) and for each Color, check the color of the eight pixels around that pixel. If those pixels do not match the current pixel closely enough, consider the current pixel an edge.</p>
  
  <p>Here's the basic code that defines if a pixel is an edge. It takes in a Color[] of nine colors, the first of which is the pixel is to check.</p>
  
  <pre><code>public Boolean isEdgeOptimized(Color[] colors)
  {
      //colors[0] should be the checking pixel
      Boolean returnBool = true;
      float percentage = percentageInt; //the percentage used is set
      //equal to the global variable percentageInt
  
      if (isMatching(colors[0], colors[1], percentage) &amp;&amp;
              isMatching(colors[0], colors[2], percentage) &amp;&amp;
              isMatching(colors[0], colors[3], percentage) &amp;&amp;
              isMatching(colors[0], colors[4], percentage) &amp;&amp;
              isMatching(colors[0], colors[5], percentage) &amp;&amp;
              isMatching(colors[0], colors[6], percentage) &amp;&amp;
              isMatching(colors[0], colors[7], percentage) &amp;&amp;
              isMatching(colors[0], colors[8], percentage))
      {
          returnBool = false;
      }
      return returnBool;
  }
  </code></pre>
  
  <p>This code is applied for every pixel, the colors of which are fetched using lockbits.</p>
  
  <p>So basically, the question is, how can I get my program to run faster? Is it my algorithm, or is there something I can use that is faster than lockBits?</p>
  
  <p>By the way, the project is on gitHub, <a href="https://github.com/vkoves/EdgeDetection" rel="nofollow noreferrer">here</a></p>