Created
November 11, 2012 19:24
-
-
Save makc/4055965 to your computer and use it in GitHub Desktop.
Integral image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
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
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++;
}