title: HTML5 Canvas Enhance Image
body: <p>I have the following function to brighten/darken an image.</p>
  
  <pre><code>&lt;script&gt;
  brightness = function(delta) {
      return function (pixels, args) {
          var d = pixels.data;
          for (var i = 0; i &lt; d.length; i += 4) {
              d[i] += delta;     // red
              d[i + 1] += delta; // green
              d[i + 2] += delta; // blue   
          }
          return pixels;
      };
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>Just want to try out something more interesting, is it possible that I can perform auto enhancement to an image? What I mean is to brighten/darken only certain area in a photo. How should I go about detecting if the pixel is dark for example, then I should brighten it slightly? Thanks.</p>