How to save posterized pixel color values from webcam

Hello! I’m looking to make a video ‘mirror’ using the webcam. I’m using the processing example Contributed Libraries > Video > Capture > Mirror by Daniel Shiffman.

The effect I’m trying to create requires using a posterized image, which means I have to apply the posterize effect to the webcam image, then save the posterized pixel color data to be used by the mirror. My question is how to do this!

I’m grabbing the webcam pixel color data using the r, g and b variables within the loop below. The loop is within void draw();

<
if (video.available()) {

video.read();
video.loadPixels();

  randomSeed(0);

// Begin loop for columns
for (int i = 0; i < cols; i++) {
  // Begin loop for rows
  for (int j = 0; j < rows; j+=3) {
  
    // Where are we, pixel-wise?
    int x = i*cellSize;
    int y = j*cellSize;
    int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
  
    float r = red(video.pixels[loc]);
    float g = green(video.pixels[loc]);
    float b = blue(video.pixels[loc]);
    // Make a new color
    color c = color(r, g, b);

    rectMode(CENTER);
    fill(c);
    noStroke();
    if ( i % 2 == 0 ){
      ellipse(x, y, cellSize, cellSize*5);
    } else {
      ellipse(x, y+15, cellSize, cellSize*5);
    }
  }
}

}

/>