diff --git a/8thWeek/Canny/Canny.pde b/8thWeek/Canny/Canny.pde index 0cd579b..48aa885 100644 --- a/8thWeek/Canny/Canny.pde +++ b/8thWeek/Canny/Canny.pde @@ -1,68 +1,168 @@ -PImage img; -PImage board1Thresholded; -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"); - noLoop(); // no interactive behaviour: draw() will be called only once. -} - -void draw() { - image(img, 0, 0);//show image - PImage img2 = img.copy();//make a deep copy - img2.loadPixels();// load pixels - - //img2=threshold(img2, (int)map(thresholdBar.getPos(),0,1,0,255), false); - //img2=HueMap(img2, thresholdBar0.getPos(), thresholdBar1.getPos()); - img2=thresholdHSB(img2, 100, 200, 100, 255, 45, 100 ); - - img2.updatePixels();//update pixels - image(img2, img.width, 0); - /*thresholdBar0.display(); - thresholdBar0.update(); - thresholdBar1.display(); - thresholdBar1.update();*/ - - println(imagesEqual(img2,board1Thresholded)); -} - -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])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; + } + } + // - sum all these intensities and divide it by normFactor + // - set result.pixels[y * img.width + x] to this value + float value = sqrt(pow(sum_h, 2) + pow(sum_v, 2)); + max = (value > max )? value : max; + buffer[x+y*img.width] = value / normFactor; + } + } + + // ************************************* + 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 the gaussian kernel + 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]); + } + } + // - sum all these intensities and divide it by normFactor + // - set result.pixels[y * img.width + x] to this value + result.pixels[x+y*img.width] = color((int)(sum / normFactor)); + } + } + + return result; +} diff --git a/Project/Game/board1.jpg b/Project/Game/board1.jpg new file mode 100644 index 0000000..8766422 Binary files /dev/null and b/Project/Game/board1.jpg differ diff --git a/Project/Game/board1Blurred.bmp b/Project/Game/board1Blurred.bmp new file mode 100644 index 0000000..7eb8be8 Binary files /dev/null and b/Project/Game/board1Blurred.bmp differ diff --git a/Project/Game/board1Scharr.bmp b/Project/Game/board1Scharr.bmp new file mode 100644 index 0000000..688672d Binary files /dev/null and b/Project/Game/board1Scharr.bmp differ diff --git a/Project/Game/board1Thresholded.bmp b/Project/Game/board1Thresholded.bmp new file mode 100644 index 0000000..318f1de Binary files /dev/null and b/Project/Game/board1Thresholded.bmp differ diff --git a/Project/Game/board2.jpg b/Project/Game/board2.jpg new file mode 100644 index 0000000..dd326b2 Binary files /dev/null and b/Project/Game/board2.jpg differ diff --git a/Project/Game/board3.jpg b/Project/Game/board3.jpg new file mode 100644 index 0000000..8c1bbd3 Binary files /dev/null and b/Project/Game/board3.jpg differ diff --git a/Project/Game/board4.jpg b/Project/Game/board4.jpg new file mode 100644 index 0000000..34fa5cc Binary files /dev/null and b/Project/Game/board4.jpg differ diff --git a/Project/Game/nao.jpg b/Project/Game/nao.jpg new file mode 100644 index 0000000..1bce331 Binary files /dev/null and b/Project/Game/nao.jpg differ