int width; // width of the image int height; // height of the image byte image[width*height]; // current image byte updatingMask[*height]; // updating mask (1==updating allowed) int subsamplingFactor = 16; // amount of random subsampling int numberOfSamples = 20; // number of samples per pixel byte samples[width*height][numberOfSamples]; // background model for (int p = 0; p < width*height; p++) if (updatingMask[p] == 1) { // updating is allowed // eventually updates the model of p (in-place updating) int randomNumber = getRandomIntegerIn(1, subsamplingFactor); if (randomNumber == 1) { // random subsampling // randomly selects a sample in the model to be replaced int randomNumber = getRandomIntegerIn(0, numberOfSamples - 1); samples[p][randomNumber] = image[p]; } // eventually diffuses in a neighboring model (spatial diffusion) int randomNumber = getRandomIntegerIn(1, subsamplingFactor); if (randomNumber == 1) { // random subsampling // chooses a neighboring pixel randomly q = getPixelLocationFromTheNeighborhoodOf(p); // diffuses the current value in the model of q // (uncomment the following check to inhibit diffusion across the border of the updating mask) // if (updatingMask[q] == 1) { int randomNumber = getRandomIntegerIn(0, numberOfSamples - 1); samples[q][randomNumber] = image[p]; // } } } // end of "if" } // end of "for"