Skip to content

Instantly share code, notes, and snippets.

@makc
Created November 11, 2012 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makc/4055965 to your computer and use it in GitHub Desktop.
Save makc/4055965 to your computer and use it in GitHub Desktop.
Integral image
var w:int = bitmapData.width, w1:int = w + 1, w2:int = w + 2, h:int = bitmapData.height, h1:int = h + 1, length:int = w1 * h1;
var integralImage:Vector.<int> = new Vector.<int> (length, true);
var vec:Vector.<uint> = bitmapData.getVector (bitmapData.rect);
var i/*nput*/:int = 0, o/*utput*/:int = w2, s:int;
for (var y:int = 0; y < h; y++, o++) {
s = 0;
for (var x:int = 0; x < w; x++, o++, i++) {
// * iI[o-w1]
// s iI[o]
s += vec [i] & 255;
integralImage [o] = integralImage[int (o - w1)] + s;
}
}
@inspirit
Copy link

well it looks easier but it slower actually :) because u are doing more read ops then needed
p = w1 + 1;
pup = 1;

for ( y = 0; y < h; ++y ) {
s = 0;
for ( x = 0; x < w; ++x ) {
s += vec[i]&0xff;
ii[p++] = ii[pup++] + s;
}
p++;
pup++;
}

@makc
Copy link
Author

makc commented Nov 11, 2012

By "easier" I mean no if-s or 2nd loops. Agreed on "s" vs "[...]" part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment