Original Post
Hi guys, I'm trying to compute average color values of an grayscale image blocks. My grayscale image is divided into 64 blocks(think of it like placing a 8x8 grid on the image, hence each block size is image width/8 and image height/8. Here is my source code, But when I try it on some images that are not multiple of 8, it crashes. Can somebody explain me what I'm doing wrong ? [Edited by - Great_White on November 21, 2008 1:17:51 AM]
static void averageColorOf8x8_Blocks(unsigned char* img, int width, int height, long avgc[8][8]) {
// validate arguments
assert(img);
assert(width);
assert(height);
// calculate block size(block width x block height)
int blck_w= width/8, blck_h=height/8;
// compute average of each block(to get 64 color values)
for(int y=0;y<height;y+=blck_h) { // for each vertical block
for(int x=0;x<width;x+=blck_w) { // for each horizontal block
for(int z=0;z<blck_h;++z) { // for each block entry
for(int w=0;w<blck_w;++w) {
avgc[y/blck_h][x/blck_w] += (long)img[(y+z)*width +x+w ];
}
}
avgc[y/blck_h][x/blck_w] *= 1/(blck_w*blck_h); // average
}
}
}