PImage img; PImage board1Thresholded, board1Blurred, board1Scharr; HScrollbar thresholdBar0; HScrollbar thresholdBar1; void settings() { size(1600, 600); } void setup() { thresholdBar0 = new HScrollbar(0, 560, 800, 20); thresholdBar1 = new HScrollbar(0, 580, 800, 20); img = loadImage("src/board1.jpg"); board1Thresholded = loadImage("src/board1Thresholded.bmp"); board1Blurred = loadImage("src/board1Blurred.bmp"); board1Scharr = loadImage("src/board1Scharr.bmp"); noLoop(); // no interactive behaviour: draw() will be called only once. } void draw() { image(img, 0, 0);//show image PImage img2,img3,img4; //img2=threshold(img2, (int)map(thresholdBar.getPos(),0,1,0,255), false); //img2=HueMap(img2, thresholdBar0.getPos(), thresholdBar1.getPos()); img2 = thresholdHSB(img, 100, 200, 100, 255, 45, 100 ); img3 = convolute(img); img4 = scharr(img); image(img2, img.width, 0); /*thresholdBar0.display(); thresholdBar0.update(); thresholdBar1.display(); thresholdBar1.update();*/ println(imagesEqual(img2, board1Thresholded)); println(imagesEqual(img3, board1Blurred)); println(imagesEqual(img4, board1Scharr)); } PImage threshold(PImage img, int threshold, boolean inverted) { PImage result = createImage(img.width, img.height, RGB); for (int i = 0; i < img.width * img.height; i++) { result.pixels[i]=brightness(img.pixels[i])>threshold^inverted?color(255):color(0); } return result; } PImage thresholdHSB(PImage img, int minH, int maxH, int minS, int maxS, int minB, int maxB) { PImage result = createImage(img.width, img.height, RGB); for (int i = 0; i < img.width * img.height; i++) { if (hue(img.pixels[i])= img.height)? img.height-1 : row; int column = ((column = x-N/2+i) < 0)? 0 : column; column = (column >= img.width)? img.width-1: column; float brightness = brightness(img.pixels[column + img.width *row]); sum_h += hKernel[i][j] * brightness; sum_v += vKernel[i][j] * brightness; } } float value = sqrt(pow(sum_h, 2) + pow(sum_v, 2)); max = (value > max )? value : max; buffer[x+y*img.width] = value; } } // ************************************* for (int y = 1; y < img.height - 1; y++) { // Skip top and bottom edges for (int x = 1; x < img.width - 1; x++) { // Skip left and right int val=(int) ((buffer[y * img.width + x] / max)*255); result.pixels[y * img.width + x]=color(val); } } return result; } PImage convolute(PImage img) { int N = 3; //kernel size float[][] kernel1 = {{ 0, 0, 0 }, { 0, 2, 0 }, { 0, 0, 0 }}; float[][] kernel2 = {{ 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 }}; float[][] gaussianKernel = {{ 9, 12, 9 }, { 12, 15, 12 }, { 9, 12, 9 }}; float[][] kernel = gaussianKernel; float normFactor = 1.f; for (int i = 0; i< N; ++i) { for (int j = 0; j= img.height)? img.height-1 : row; int column = ((column = x-N/2+i) < 0)? 0 : column; column = (column >= img.width)? img.width-1: column; sum += kernel[i][j] * brightness(img.pixels[column + img.width *row]); } } result.pixels[x+y*img.width] = color((int)(sum / normFactor)); } } return result; }