Threshold animation problem
in
Programming Questions
•
10 months ago
Hello friends
i am trying to make it so that the program takes an image posterizes it a bit and then turns it all black and then all white using threshold but i am facing problems going further than just doing the threshold part so here is my code any help would be appreciated and thanks.
PImage source; // Source image
PImage destination; // Destination image
//boolean threshold=false;
void setup() {
size(800, 800);
source = loadImage("_MG_4515.jpg");
// The destination image is created as a blank image the same size as the source.
destination = createImage(source.width, source.height, RGB);
}
void draw() {
float threshold = 127;
// We are going to look at both image's pixels
source.loadPixels();
destination.loadPixels();
for (int x = 0; x < source.width; x++) {
for (int y = 0; y < source.height; y++ ) {
int loc = x + y*source.width;
// Test the brightness against the threshold
if (brightness(source.pixels[loc]) > threshold) {
destination.pixels[loc] = color(255); // White
}
else {
destination.pixels[loc] = color(0); // Black
}
//if (brightness(source.pixels[loc]) <color (0)) {
//threshold++; // Black
//}
//else {
// threshold--;
// }
}
}
// We changed the pixels in destination
destination.updatePixels();
// Display the destination
image(destination, 0, 0);
}
1