// Declaring a variable of type PImage PImage bike, construction; int loc; int redValue, greenValue, blueValue; int maskSize, maskSizeDiv2; float[][] mask; color[][] tempArray; float offset; int xk, yl; Boolean doCalc=false; void setup() { float[] temp1Array; //to hold lines of mask // Make a new instance of a PImage by loading an image file // construction= loadImage("construction.jpg"); float[] temp; // to hold the input line String[] lines= loadStrings("data.txt"); // println("there are " +lines.length +" lines"); construction= loadImage(lines[0]); size(construction.width, construction.height); maskSize = int(lines[1]); maskSizeDiv2= maskSize/2; // println(maskSize/2 + " " +(maskSize-1)/2); if (maskSize/2 != (maskSize-1)/2) { println("need odd mask "); exit(); } mask= new float[maskSize][maskSize]; for (int y=0; y=width) { xk=width-1; } else { xk = x+k; } if (y+l < 0 ) { yl=0; } else if (y+l>=height) { yl=height-1; } else { yl = y+l; } //println(xk + " " + yl); pixelsRed += red(tempArray[xk][yl])*mask[k+maskSizeDiv2][l+maskSizeDiv2]; pixelsGreen += green(tempArray[xk][yl])*mask[k+maskSizeDiv2][l+maskSizeDiv2]; pixelsBlue += blue(tempArray[xk][yl])*mask[k+maskSizeDiv2][l+maskSizeDiv2]; // println(pixelsRed); } // need to decide what to do with pixel values out of range iPixelsRed = int( pixelsRed + offset); iPixelsGreen = int( pixelsGreen + offset); iPixelsBlue = int( pixelsBlue + offset); if (iPixelsRed <0) iPixelsRed=0; if (iPixelsGreen <0) iPixelsGreen=0; if (iPixelsBlue <0) iPixelsBlue=0; if (iPixelsRed >255) iPixelsRed=255; if (iPixelsGreen >255) iPixelsGreen=255; if (iPixelsBlue >255) iPixelsBlue=255; color tempColor= color(iPixelsRed, iPixelsGreen, iPixelsBlue); pixels[loc]= tempColor; // print (blue(pixels[loc])+" "); // if((x+1)%width ==0)println(); } updatePixels(); // println("here"); saveFrame("filteredPic" + ".jpg"); } //println(maskSizeDiv2); // println(tempArray[maskSizeDiv2][1]); } void mouseClicked() { doCalc= true; }