Invert
PImage img;
void setup() {
colorMode(HSB, 360, 255, 255);
img = loadImage(“image.jpg”);
size(img.width, img.height);
img.loadPixels();
for (int x =0; x <img.width; x++) {
for (int y=0; y <img.height; y++) {
int i= y * img.width + x;
color c = img.pixels[i];
//println(hue(c));
float c_hue = hue (c) – 180;
//println(c_hue);
if (c_hue <0) {
c_hue= c_hue +360;
}
color c_inverted = color ( c_hue, saturation(c), brightness(c));
img.pixels[i] = c_inverted;
}
}
image(img, 0, 0);
}
Original: http://www.celebrityplus.net/wp-content/uploads/2014/05/marilyn-monroe-cosmetic-surgery.jpg
Contrast
PImage img;
void setup() {
colorMode( HSB, 360, 255, 255 );
img = loadImage(“image.jpg”);
size( img.width, img.height );
img.loadPixels();
for ( int x = 0; x < img.width; x++ ) {
for ( int y = 0; y < img.height; y++ ) {
int i = y * img.width + x;
float bright = map( brightness(img.pixels[i]), 80, 220, 0, 255);
img.pixels [i]= color( hue(img.pixels[i]), saturation(img.pixels[i]), bright);
}
}
image(img, 0, 0);
}
Original: http://monkmanphoto.com/wp-content/uploads/2012/02/Monkman_MABKS_D30112.jpg
Posterize
PImage img;
void setup() {
//colorMode(HSB, 360, 255, 255);
img = loadImage(“image.jpg”);
size(img.width, img.height);
img.loadPixels();
/***** ORIGINAL *****/
color navy = color(18, 75, 147);
color crimson = color(222, 63, 63);
color skyblue= color ( 121, 161, 227);
color cream = color( 250, 247, 232);
/***** MODIFIED *****/
/*color navy = color( 27, 42, 60 );
color crimson = color( 95, 156, 160 );
color skyblue= color ( 195, 150, 104);
color cream = color( 245, 195, 130);*/
for (int x =0; x <img.width; x++) {
for (int y=0; y <img.height; y++) {
int i= y * img.width + x;
float greyscale = (0.21 *red (img.pixels[i]) + 0.72 * green(img.pixels[i]) + 0.07 * blue(img.pixels[i]));
if (greyscale< 50 ) { img.pixels[i] = navy; } else if (greyscale > 50 && greyscale <120) { img.pixels[i] = crimson; } else if ( greyscale >120 && greyscale <170) { img.pixels[i] = skyblue; } else if (greyscale >170 && greyscale <255) {
img.pixels[i] = cream;
}
}
}
image(img, 0, 0);
textSize(32);
//textAlign(CENTER);
fill(255);
text (“Purple Haze”, 20, height – 20);
}