// PImageOperations Class for processing // (c) 2006 Andrew Senior http://www.andrewsenior.com // Preserve this header when redistributing. // class PImageOperations { // Copy Image I2 to I1. void Copy(PImage I1, PImage I2) { for(int i=0; i255) iR=255; float iG=(green(iP1)+green(iP2)); if (iG>255) iG=255; float iB=(blue(iP1)+blue(iP2)); if (iB>255) iB=255; I1.pixels[i]=color(iR, iG, iB); } } // blend one image with another (output in I1) beware quantization effects. void Blend(PImage I1, PImage I2, float fRate) { float fComp=1-fRate; for(int i=0; iiThresh*3) I1.pixels[i]=color(255,255,255); else I1.pixels[i]=color(0,0,0); } } // Binary morphology Open (black holes up) operator void MorphOpen(PImage I1, PImage I2) { int iThresh=128; int k=0; for(int j=0; jiThresh && (i==0 || red(I1.pixels[k-1])>iThresh) && (i==I1.width-1 || red(I1.pixels[k+1])>iThresh) && (j==0 || red(I1.pixels[k-I1.width])>iThresh) && (j==I1.height-1 || red(I1.pixels[k+I1.width])>iThresh) && (i==0 || j==0 || red(I1.pixels[k-1-I1.width])>iThresh) && (i==0 || j==I1.height-1 || red(I1.pixels[k-1+I1.width])>iThresh) && (i==I1.width-1 || j==0 || red(I1.pixels[k+1-I1.width])>iThresh) && (i==I1.width-1 || j==I1.height-1 || red(I1.pixels[k+1+I1.width])>iThresh) ) I2.pixels[k]=color(255,255,255); else I2.pixels[k]=color(0,0,0); } } // Binary morphology Close (black holes- enlarge white areas) void MorphClose(PImage I1, PImage I2) { int iThresh=128; int k=0; for(int j=0; jiThresh || (i!=0 && red(I1.pixels[k-1])>iThresh) || (i!=I1.width-1 && red(I1.pixels[k+1])>iThresh) || (j!=0 && red(I1.pixels[k-I1.width])>iThresh) || (j!=I1.height-1 && red(I1.pixels[k+I1.width])>iThresh) || (i!=0 && j!=0 && red(I1.pixels[k-1-I1.width])>iThresh) || (i!=0 && j!=I1.height-1 && red(I1.pixels[k-1+I1.width])>iThresh) || (i!=I1.width-1 && j!=0 && red(I1.pixels[k+1-I1.width])>iThresh) || (i!=I1.width-1 && j!=I1.height-1 && red(I1.pixels[k+1+I1.width])>iThresh) ) I2.pixels[k]=color(255,255,255); else I2.pixels[k]=color(0,0,0); } } void Put(PImage I1) { for(int i=0; i