class MakeOutputImage with anti-aliasing

In the earlier post “Smoothing and anti-aliasing” I discussed how to smooth images and reduce aliasing.This is an important part of the class MakeOutputImage. This class is rather a template for programming and not a finished module. You find its code in the next post.

You create an object of this class with

outputMaker=new MakeOutputImage(outputImage);

where outputImage is a PImage object. The actual image is created in a suitable function that returns a color depending on the coordinates of the pixel. Typically one would use here objects of the class Coordinates and ColorLookup. To test anti-aliasing I used simply

color theImage(float i,float j){
    return ripples(i,j);
  }

You get the image from

outputMaker.simple();

if you don’t want any antialiasing. With

outputMaker.block();

we use the first anti-aliasing method, using four points around each pixel. Improved anti-aliasing results from averaging nine points at each pixel with

outputMaker.tent();

which does not need much more time because lines of points are evaluated and reused for many pixels. Image filters or cellular automaton use similar methods.

Note that this class needs the class ProgressReport of the last post. The results shown in “smoothing and antialiasing” result from:

MakeOutputImage makeOutputImage;
PImage output;

void setup(){
  size(600,100);
  output=createImage(width,height,RGB);
  makeOutputImage=new MakeOutputImage(output);
}

void draw(){
  noLoop();
  makeOutputImage.tent();
//  makeOutputImage.simple();
//  makeOutputImage.block();
  image(output,0,0);
}

color ripples(float i,float j){
  return color(128*(1+cos(2*PI*i*(1+height-j)/600)),128,255*sq(cos(PI*i*j/600)));
}
This entry was posted in Extra, programming and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s