int width; // width of the image int height; // height of the image byte image[width*height]; // current image byte segmentationMap[width*height]; // classification result int distanceThreshold = 20; byte sample[width*height]; // static background model ... for (int p = 0; p < width*height; p++) { if (getDistanceBetween(image[p], sample[p]) < distanceThreshold) segmentationMap[p] = BACKGROUND_LABEL; else segmentationMap[p] = FOREGROUND_LABEL; }