Skip to content

Instantly share code, notes, and snippets.

@eduardolundgren
Created October 14, 2012 06:08
Show Gist options
  • Save eduardolundgren/3887562 to your computer and use it in GitHub Desktop.
Save eduardolundgren/3887562 to your computer and use it in GitHub Desktop.
canvas.forEach(imageData, function(r, g, b, a, w, i, j) {
pixel = ~~(r*0.299 + b*0.587 + g*0.114);
if (i === 0 & j === 0) {
pixelSum = pixel;
pixelSumSquare = pixel*pixel;
}
else if (i === 0) {
pixelSum = pixel + integralImage[i*width + (j - 1)];
pixelSumSquare = pixel*pixel + integralImageSquare[i*width + (j - 1)];
}
else if (j === 0) {
pixelSum = pixel + integralImage[(i - 1)*width + j];
pixelSumSquare = pixel*pixel + integralImageSquare[(i - 1)*width + j];
}
else {
pixelSum = pixel + integralImage[i*width + (j - 1)] + integralImage[(i - 1)*width + j] - integralImage[(i - 1)*width + (j - 1)];
pixelSumSquare = pixel*pixel + integralImageSquare[i*width + (j - 1)] + integralImageSquare[(i - 1)*width + j] - integralImageSquare[(i - 1)*width + (j - 1)];
}
// pixelSumSquare += pixel*pixel;
integralImage[imageLen] = pixelSum;
integralImageSquare[imageLen] = pixelSumSquare;
imageLen++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment