topical media & game development

talk show tell print

graphic-processing-algorithm-Ch05-p111-p111.pde / pde



  PImage myImage; //define an image object
  myImage = loadImage("memorial.jpg"); //load it
  size(myImage.width,myImage.height); //size it to fit the window
  image(myImage, 0,0); //display the image
  int filter = 1; //choose a filter
  switch(filter) {
  case 1:
    filter(THRESHOLD, .6); //every pixel below .6 becomes black
    break;
  case 2:
    filter(GRAY); //all pixels get the average value of their rgb
    break;
  case 3:
    filter(INVERT); //all pixels get the opposite value of their rgb
    break; // (i.e. 255-r)
  case 4:
    filter(POSTERIZE, 2); //limits each channel of the image to 2
    break; // colors
  case 5:
    filter(BLUR, 1); // executes a Guassian blur with radius 1
    break;
  case 6:
    filter(BLUR, 6); // executes a Guassian blur with radius 6
    break;
  }
  save("memorial_filter_"+filter+".jpg"); // save the image
  // as a numbered file


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.