User:Simpsons contributor/Useful Java image storer and processor class. Self made

package newtonsmethodfractal;

import java.awt.Color; import java.awt.image.BufferedImage;

public class ImageProcessor {   private BufferedImage image; public ImageProcessor(BufferedImage imageIn) {       image = imageIn; }   public ImageProcessor(int width, int height) {       int TYPE = BufferedImage.TYPE_INT_RGB; image = new BufferedImage(width, height, TYPE); }   public int getWidth {       return image.getWidth; }   public int getHeight {       return image.getHeight; }   public BufferedImage getImage {       return image; }   public void resetImage(BufferedImage imageIn) {       image = imageIn; }   public void lineSimple(int x0, int y0, int x1, int y1, int rgb) {       int dx = x1 - x0; int dy = y1 - y0;

if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); if (dx != 0) {           float m = (float) dy / (float) dx; float b = y0 - m*x0; dx = (x1 > x0) ? 1 : -1;           while (x0 != x1) { x0 += dx; y0 = Math.round(m*x0 + b); if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); }       }    }    public void lineImproved(int x0, int y0, int x1, int y1, int rgb) {       int dx = x1 - x0; int dy = y1 - y0;

if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); if (Math.abs(dx) > Math.abs(dy)) {         // slope < 1 float m = (float) dy / (float) dx;     // compute slope float b = y0 - m*x0; dx = (dx < 0) ? -1 : 1;           while (x0 != x1) { x0 += dx; if(boundsTest(image, x0, Math.round(m*x0 + b)) == true) image.setRGB(x0, Math.round(m*x0 + b), rgb); }       } else if (dy != 0) {                             // slope >= 1 float m = (float) dx / (float) dy;     // compute slope float b = x0 - m*y0; dy = (dy < 0) ? -1 : 1;           while (y0 != y1) { y0 += dy; if(boundsTest(image, Math.round(m*y0 + b), y0) == true) image.setRGB(Math.round(m*y0 + b), y0, rgb); }       }    }    public void lineDDA(int x0, int y0, int x1, int y1, int rgb) {       int dy = y1 - y0; int dx = x1 - x0; float t = (float) 0.5;                     // offset for rounding

if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); if (Math.abs(dx) > Math.abs(dy)) {         // slope < 1 float m = (float) dy / (float) dx;     // compute slope t += y0; dx = (dx < 0) ? -1 : 1;           m *= dx; while (x0 != x1) { x0 += dx;                          // step to next x value t += m;                            // add slope to y value if(boundsTest(image, x0, (int) t) == true) image.setRGB(x0, (int) t, rgb); }       } else {                                    // slope >= 1 float m = (float) dx / (float) dy;     // compute slope t += x0; dy = (dy < 0) ? -1 : 1;           m *= dy; while (y0 != y1) { y0 += dy;                          // step to next y value t += m;                            // add slope to x value if(boundsTest(image, (int) t, y0) == true) image.setRGB((int) t, y0, rgb); }       }    }    public void lineBresenham(int x0, int y0, int x1, int y1, int rgb) {       int dy = y1 - y0; int dx = x1 - x0; int stepx, stepy;

if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; } if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } dy <<= 1;                                                 // dy is now 2*dy dx <<= 1;                                                 // dx is now 2*dx

if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); if (dx > dy) { int fraction = dy - (dx >> 1);                        // same as 2*dy - dx            while (x0 != x1) { if (fraction >= 0) { y0 += stepy; fraction -= dx;                               // same as fraction -= 2*dx }               x0 += stepx; fraction += dy;                                   // same as fraction -= 2*dy if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); }       } else { int fraction = dx - (dy >> 1); while (y0 != y1) { if (fraction >= 0) { x0 += stepx; fraction -= dy; }               y0 += stepy; fraction += dx; if(boundsTest(image, x0, y0) == true) image.setRGB(x0, y0, rgb); }       }    }    public void thickLine(int x0, int y0, int x1, int y1, int thickness,                          int lineType, int rgb) {       /*Draws many lines next to one another to provide a thicker line. * the number of lines drawn next to one anothe will be equal * to thickness. Each new line will be "below" the previous one; * so line one will be (x0, y0, x1, y1) the second will be        * (x0, y0+1, x1, y1+1). lineType determines the type of line detection * algorithm to be used: * 1) lineSimple        * 2) lineImproved * 3) lineDDA        * 4) lineBresenham*/ //Draw using lineSimple if(lineType == 1) {           for(int i=0; i<thickness; i++) lineSimple(x0, y0+i, x1, y1+i, rgb); }              //Draw using lineImproved if(lineType == 2) {           for(int i=0; i<thickness; i++) lineImproved(x0, y0+i, x1, y1+i, rgb); }           //Draw using lineDDA if(lineType == 3) {           for(int i=0; i<thickness; i++) lineDDA(x0, y0+i, x1, y1+i, rgb); }           //Draw using lineBresenham if(lineType == 4) {           for(int i=0; i<thickness; i++) lineBresenham(x0, y0+i, x1, y1+i, rgb); }               }       public void drawCirlce(int xCenter, int yCenter, int radius, int rgb) {       int x, y, r2;

r2 = radius * radius; if(boundsTest(image, xCenter, yCenter + radius) == true) image.setRGB(xCenter, yCenter + radius, rgb); if(boundsTest(image, xCenter, yCenter - radius) == true) image.setRGB(xCenter, yCenter - radius, rgb); if(boundsTest(image, xCenter + radius, yCenter) == true) image.setRGB(xCenter + radius, yCenter, rgb); if(boundsTest(image, xCenter - radius, yCenter) == true) image.setRGB(xCenter - radius, yCenter, rgb);

y = radius; x = 1; y = (int) (Math.sqrt(r2 - 1) + 0.5); while (x < y) { if(boundsTest(image, xCenter + x, yCenter + y) == true) image.setRGB(xCenter + x, yCenter + y, rgb); if(boundsTest(image, xCenter + x, yCenter - y) == true) image.setRGB(xCenter + x, yCenter - y, rgb); if(boundsTest(image, xCenter - x, yCenter + y) == true) image.setRGB(xCenter - x, yCenter + y, rgb); if(boundsTest(image, xCenter - x, yCenter - y) == true) image.setRGB(xCenter - x, yCenter - y, rgb); if(boundsTest(image, xCenter + y, yCenter + x) == true) image.setRGB(xCenter + y, yCenter + x, rgb); if(boundsTest(image, xCenter + y, yCenter - x) == true) image.setRGB(xCenter + y, yCenter - x, rgb); if(boundsTest(image, xCenter - y, yCenter + x) == true) image.setRGB(xCenter - y, yCenter + x, rgb); if(boundsTest(image, xCenter - y, yCenter - x) == true) image.setRGB(xCenter - y, yCenter - x, rgb); x += 1; y = (int) (Math.sqrt(r2 - x*x) + 0.5); }       if (x == y) { if(boundsTest(image, xCenter + x, yCenter + y) == true) image.setRGB(xCenter + x, yCenter + y, rgb); if(boundsTest(image, xCenter + x, yCenter - y ) == true) image.setRGB(xCenter + x, yCenter - y, rgb); if(boundsTest(image, xCenter - x, yCenter + y) == true) image.setRGB(xCenter - x, yCenter + y, rgb); if(boundsTest(image, xCenter - x, yCenter - y) == true) image.setRGB(xCenter - x, yCenter - y, rgb); }   }        public void drawRectangle(int x, int y, int width, int height, int rgb) {       /*Draws a rectangle with the top left corner at (x, y), * the top right corner at (x+width, y), the bottom left * corner at (x, y+height) and the bottom right corner at        * (x+width, y+height). The four lines are number coded: *         *      tl     1         tr         *      -- *     |                |         *   2  |                |  3         *      |                |         *      --         *      bl     4         br                   */ //Draw line 1 (tl -> tr) (x, y) -> (x+width, y)       lineImproved(x, y, x+width, y, rgb); //Draw line 2 (tl -> bl) (x, y) -> (x, y+height) lineImproved(x, y, x, y+height, rgb); //Draw line 3 (tr -> br) (x+width, y) -> (x+width, y+height) lineImproved(x+width, y, x+width, y+height, rgb); //Draw line 4 (bl -> br) (x, y+height) -> (x+width, y+height) lineImproved(x, y+height, x+width, y+height, rgb); }   public void drawSquare(int x, int y, int length, int rgb) {       //Draw a rectangle with equal width and height drawRectangle(x, y, length, length, rgb); }   public void drawFilledRectangle(int x, int y, int width, int height, int rgb) {       while(width > 0 && height > 0) {           drawRectangle(x, y, width, height, rgb); width--; height--; }   }    public void drawFilledSquare(int x, int y, int length, int rgb) {       while(length > 0) {           drawSquare(x, y, length, rgb); length--; }   }    public void addRandomColour(int x, int y)    { int red = random255; int green = random255; int blue = random255; int rgb = convertRGB(red, green, blue); image.setRGB(x, y, rgb); }         private boolean boundsTest(BufferedImage image, int x, int y)    { boolean result = true; if(x >= image.getWidth) result = false; if(y >= image.getHeight) result = false; if(x < 0) result = false; if(y < 0) result = false; return result; }   private int random255 {       double randomDouble = Math.random; Number randomNumber = 255 * randomDouble; return randomNumber.intValue; }   public int redNegative(int x, int y)    { return 255 - getRed(x, y); }   public int greenNegative(int x, int y)    { return 255 - getGreen(x, y); }   public int blueNegative(int x, int y)    { return 255 - getBlue(x, y); }   public int greyNegative(int x, int y)    { return 255 - getGrey(x, y); }       public int redGaussian(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-2, y >= height-2, x < 2 and y < 2. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-2 || y >= height-2 || x < 2 || y < 2) return 0; else return redGaussianInside(x, y); }   public int greenGaussian(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-2, y >= height-2, x < 2 and y < 2. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-2 || y >= height-2 || x < 2 || y < 2) return 0; else return greenGaussianInside(x, y); }   public int greyGaussian(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-2, y >= height-2, x < 2 and y < 2. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-2 || y >= height-2 || x < 2 || y < 2) return 0; else return greyGaussianInside(x, y); }   public int blueGaussian(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-2, y >= height-2, x < 2 and y < 2. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-2 || y >= height-2 || x < 2 || y < 2) return 0; else return blueGaussianInside(x, y); }   private int redGaussianInside(int x, int y)    { int z1 = getRed(x-2, y-2); int z2 = getRed(x-1, y-2); int z3 = getRed(x, y-2); int z4 = getRed(x+1, y-2); int z5 = getRed(x+2, y-2); int z6 = getRed(x-2, y-1); int z7 = getRed(x-1, y-1); int z8 = getRed(x, y-1); int z9 = getRed(x+1, y-1); int z10 = getRed(x+2, y-1); int z11 = getRed(x-2, y); int z12 = getRed(x-1, y); int z13 = getRed(x, y); int z14 = getRed(x+1, y); int z15 = getRed(x+2, y); int z16 = getRed(x-2, y+1); int z17 = getRed(x-1, y+1); int z18 = getRed(x, y+1); int z19 = getRed(x+1, y+1); int z20 = getRed(x+2, y+1); int z21 = getRed(x-2, y+2); int z22 = getRed(x-1, y+2); int z23 = getRed(x, y+2); int z24 = getRed(x+1, y+2); int z25 = getRed(x+2, y+2); int row1 = 2*z1 + 4* z2 + 5* z3 + 4* z4 + 2* z5; int row2 = 4* z6 + 9* z7 + 12*z8 + 9* z9 + 4* z10; int row3 = 5* z11 + 12* z12 + 15* z13 + 12* z14 + 5* z15; int row4 = 4* z16 + 9* z17 + 12* z18 + 9* z19 + 4* z20; int row5 = 2*z21 + 4* z22 + 5* z23 + 4* z24 + 2*z25; return (row1 + row2 + row3 + row4 + row5) / 159; }   private int greenGaussianInside(int x, int y)    { int z1 = getGreen(x-2, y-2); int z2 = getGreen(x-1, y-2); int z3 = getGreen(x, y-2); int z4 = getGreen(x+1, y-2); int z5 = getGreen(x+2, y-2); int z6 = getGreen(x-2, y-1); int z7 = getGreen(x-1, y-1); int z8 = getGreen(x, y-1); int z9 = getGreen(x+1, y-1); int z10 = getGreen(x+2, y-1); int z11 = getGreen(x-2, y); int z12 = getGreen(x-1, y); int z13 = getGreen(x, y); int z14 = getGreen(x+1, y); int z15 = getGreen(x+2, y); int z16 = getGreen(x-2, y+1); int z17 = getGreen(x-1, y+1); int z18 = getGreen(x, y+1); int z19 = getGreen(x+1, y+1); int z20 = getGreen(x+2, y+1); int z21 = getGreen(x-2, y+2); int z22 = getGreen(x-1, y+2); int z23 = getGreen(x, y+2); int z24 = getGreen(x+1, y+2); int z25 = getGreen(x+2, y+2); int row1 = 2* z1 + 4* z2 + 5* z3 + 4* z4 + 2* z5; int row2 = 4* z6 + 9* z7 + 12*z8 + 9* z9 + 4* z10; int row3 = 5* z11 + 12* z12 + 15* z13 + 12* z14 + 5* z15; int row4 = 4* z16 + 9* z17 + 12* z18 + 9* z19 + 4* z20; int row5 = 2*z21 + 4* z22 + 5* z23 + 4* z24 + 2*z25; return (row1 + row2 + row3 + row4 + row5) / 159; }

private int blueGaussianInside(int x, int y)   { int z1 = getBlue(x-2, y-2); int z2 = getBlue(x-1, y-2); int z3 = getBlue(x, y-2); int z4 = getBlue(x+1, y-2); int z5 = getBlue(x+2, y-2); int z6 = getBlue(x-2, y-1); int z7 = getBlue(x-1, y-1); int z8 = getBlue(x, y-1); int z9 = getBlue(x+1, y-1); int z10 = getBlue(x+2, y-1); int z11 = getBlue(x-2, y); int z12 = getBlue(x-1, y); int z13 = getBlue(x, y); int z14 = getBlue(x+1, y); int z15 = getBlue(x+2, y); int z16 = getBlue(x-2, y+1); int z17 = getBlue(x-1, y+1); int z18 = getBlue(x, y+1); int z19 = getBlue(x+1, y+1); int z20 = getBlue(x+2, y+1); int z21 = getBlue(x-2, y+2); int z22 = getBlue(x-1, y+2); int z23 = getBlue(x, y+2); int z24 = getBlue(x+1, y+2); int z25 = getBlue(x+2, y+2); int row1 = 2* z1 + 4* z2 + 5* z3 + 4* z4 + 2* z5; int row2 = 4* z6 + 9* z7 + 12*z8 + 9* z9 + 4* z10; int row3 = 5* z11 + 12* z12 + 15* z13 + 12* z14 + 5* z15; int row4 = 4* z16 + 9* z17 + 12* z18 + 9* z19 + 4* z20; int row5 = 2*z21 + 4* z22 + 5* z23 + 4* z24 + 2*z25; return (row1 + row2 + row3 + row4 + row5) / 159; }   private int greyGaussianInside(int x, int y)    { int z1 = getGrey(x-2, y-2); int z2 = getGrey(x-1, y-2); int z3 = getGrey(x, y-2); int z4 = getGrey(x+1, y-2); int z5 = getGrey(x+2, y-2); int z6 = getGrey(x-2, y-1); int z7 = getGrey(x-1, y-1); int z8 = getGrey(x, y-1); int z9 = getGrey(x+1, y-1); int z10 = getGrey(x+2, y-1); int z11 = getGrey(x-2, y); int z12 = getGrey(x-1, y); int z13 = getGrey(x, y); int z14 = getGrey(x+1, y); int z15 = getGrey(x+2, y); int z16 = getGrey(x-2, y+1); int z17 = getGrey(x-1, y+1); int z18 = getGrey(x, y+1); int z19 = getGrey(x+1, y+1); int z20 = getGrey(x+2, y+1); int z21 = getGrey(x-2, y+2); int z22 = getGrey(x-1, y+2); int z23 = getGrey(x, y+2); int z24 = getGrey(x+1, y+2); int z25 = getGrey(x+2, y+2); int row1 = 2* z1 + 4* z2 + 5* z3 + 4* z4 + 2* z5; int row2 = 4* z6 + 9* z7 + 12*z8 + 9* z9 + 4* z10; int row3 = 5* z11 + 12* z12 + 15* z13 + 12* z14 + 5* z15; int row4 = 4* z16 + 9* z17 + 12* z18 + 9* z19 + 4* z20; int row5 = 2*z21 + 4* z22 + 5* z23 + 4* z24 + 2*z25; return (row1 + row2 + row3 + row4 + row5) / 159; }   public int redMean(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return redMeanInside(x, y); }   public int greenMean(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return greenMeanInside(x, y); }   public int blueMean(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return blueMeanInside(x, y); }   public int greyMean(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return greyMeanInside(x, y); }

private int redMeanInside(int x, int y)   { int z1 = getRed(x-1, y-1); int z2 = getRed(x, y-1); int z3 = getRed(x+1, y-1); int z4 = getRed(x-1, y); int z5 = getRed(x, y); int z6 = getRed(x+1, y); int z7 = getRed(x-1, y+1); int z8 = getRed(x, y+1); int z9 = getRed(x+1, y+1); return (z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9) / 9; }   private int greenMeanInside(int x, int y)    { int z1 = getGreen(x-1, y-1); int z2 = getGreen(x, y-1); int z3 = getGreen(x+1, y-1); int z4 = getGreen(x-1, y); int z5 = getGreen(x, y); int z6 = getGreen(x+1, y); int z7 = getGreen(x-1, y+1); int z8 = getGreen(x, y+1); int z9 = getGreen(x+1, y+1); return (z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9) / 9; }   private int blueMeanInside(int x, int y)    { int z1 = getBlue(x-1, y-1); int z2 = getBlue(x, y-1); int z3 = getBlue(x+1, y-1); int z4 = getBlue(x-1, y); int z5 = getBlue(x, y); int z6 = getBlue(x+1, y); int z7 = getBlue(x-1, y+1); int z8 = getBlue(x, y+1); int z9 = getBlue(x+1, y+1); return (z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9) / 9; }   private int greyMeanInside(int x, int y)    { int z1 = getGrey(x-1, y-1); int z2 = getGrey(x, y-1); int z3 = getGrey(x+1, y-1); int z4 = getGrey(x-1, y); int z5 = getGrey(x, y); int z6 = getGrey(x+1, y); int z7 = getGrey(x-1, y+1); int z8 = getGrey(x, y+1); int z9 = getGrey(x+1, y+1); return (z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9) / 9; }   public int redSobel(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return redSobelInside(x, y); }   public int greenSobel(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return greenSobelInside(x, y); }   public int blueSobel(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return blueSobelInside(x, y); }   public int greySobel(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 1 and y < 1. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 1 || y < 1) return 0; else return greySobelInside(x, y); }   private int redSobelInside(int x, int y)    { int z1 = getRed(x-1, y-1); int z2 = getRed(x, y-1); int z3 = getRed(x+1, y-1); int z4 = getRed(x-1, y); int z6 = getRed(x+1, y); int z7 = getRed(x-1, y+1); int z8 = getRed(x, y+1); int z9 = getRed(x+1, y+1); int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int greenSobelInside(int x, int y)    { int z1 = getGreen(x-1, y-1); int z2 = getGreen(x, y-1); int z3 = getGreen(x+1, y-1); int z4 = getGreen(x-1, y); int z6 = getGreen(x+1, y); int z7 = getGreen(x-1, y+1); int z8 = getGreen(x, y+1); int z9 = getGreen(x+1, y+1); int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int blueSobelInside(int x, int y)    { int z1 = getBlue(x-1, y-1); int z2 = getBlue(x, y-1); int z3 = getBlue(x+1, y-1); int z4 = getBlue(x-1, y); int z6 = getBlue(x+1, y); int z7 = getBlue(x-1, y+1); int z8 = getBlue(x, y+1); int z9 = getBlue(x+1, y+1); int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); return Math.abs(gX) + Math.abs(gY); }   private int greySobelInside(int x, int y)    { int z1 = getGrey(x-1, y-1); int z2 = getGrey(x, y-1); int z3 = getGrey(x+1, y-1); int z4 = getGrey(x-1, y); int z6 = getGrey(x+1, y); int z7 = getGrey(x-1, y+1); int z8 = getGrey(x, y+1); int z9 = getGrey(x+1, y+1); int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   public int redRoberts(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 0 and y < 0. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 0 || y < 0) return 0; else return redRobertsInside(x, y); }   public int greenRoberts(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 0 and y < 0. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 0 || y < 0) return 0; else return greenRobertsInside(x, y); }   public int blueRoberts(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 0 and y < 0. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 0 || y < 0) return 0; else return blueRobertsInside(x, y); }   public int greyRoberts(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-1, y >= height-1, x < 0 and y < 0. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-1 || y >= height-1 || x < 0 || y < 0) return 0; else return greyRobertsInside(x, y); }   private int redRobertsInside(int x, int y)    { int z1 = getRed(x, y); int z2 = getRed(x+1, y); int z3 = getRed(x, y+1); int z4 = getRed(x+1, y+1); int gX = z1 - z4; int gY = z2 - z3; int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int greenRobertsInside(int x, int y)    { int z1 = getGreen(x, y); int z2 = getGreen(x+1, y); int z3 = getGreen(x, y+1); int z4 = getGreen(x+1, y+1); int gX = z1 - z4; int gY = z2 - z3;; int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int blueRobertsInside(int x, int y)    { int z1 = getBlue(x, y); int z2 = getBlue(x+1, y); int z3 = getBlue(x, y+1); int z4 = getBlue(x+1, y+1); int gX = z1 - z4; int gY = z2 - z3; int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int greyRobertsInside(int x, int y)    { int z1 = getGrey(x, y); int z2 = getGrey(x+1, y); int z3 = getGrey(x, y+1); int z4 = getGrey(x+1, y+1); int gX = z1 - z4; int gY = z2 - z3; int sumTest = Math.abs(gX) + Math.abs(gY); if(sumTest <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }       public int redReceptiveField(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-4, y >= height-4, x < 4 and y < 4. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 4 || y < 4) return 0; else return redReceptiveFieldInside(x, y); }   public int greenReceptiveField(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-4, y >= height-4, x < 4 and y < 4. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 4 || y < 4) return 0; else return greenReceptiveFieldInside(x, y); }   public int blueReceptiveField(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-4, y >= height-4, x < 4 and y < 4. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 4 || y < 4) return 0; else return blueReceptiveFieldInside(x, y); }   public int greyReceptiveField(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-4, y >= height-4, x < 4 and y < 4. Return black if they are, * else return the Gaussian at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 4 || y < 4) return 0; else return greyReceptiveFieldInside(x, y); }   private int redReceptiveFieldInside(int x, int y)    { int c1 = getRed(x, y-1); int c2 = getRed(x+1, y-1); int c3 = getRed(x-1, y); int c4 = getRed(x, y); int c5 = getRed(x+1, y); int c6 = getRed(x+2, y); int c7 = getRed(x-1, y+1); int c8 = getRed(x, y+1); int c9 = getRed(x+1, y+1); int c10 = getRed(x+2, y+1); int c11 = getRed(x, y+2); int c12 = getRed(x+1, y+2); int MeanInsideCentre = (c1 + c2 + c3 + c4 + c5 + c6 +                     c7 + c8 + c9 + c10 + c11 + c12) / 12; int s1 = getRed(x-1, y-3); int s2 = getRed(x, y-3); int s3 = getRed(x+1, y-3); int s4 = getRed(x+2, y-3); int s5 = getRed(x-2, y-2); int s6 = getRed(x-1, y-2); int s7 = getRed(x, y-2); int s8 = getRed(x+1, y-2); int s9 = getRed(x+2, y-2); int s10 = getRed(x+3, y-2); int s11 = getRed(x-3, y-1); int s12 = getRed(x-2, y-1); int s13 = getRed(x-1, y-1); int s14 = getRed(x+1, y-1); int s15 = getRed(x+2, y-1); int s16 = getRed(x+3, y-1); int s17 = getRed(x-3, y); int s18 = getRed(x-2, y); int s19 = getRed(x+3, y); int s20 = getRed(x+4, y); int s21 = getRed(x-3, y+1); int s22 = getRed(x-2, y+1); int s23 = getRed(x+3, y+1); int s24 = getRed(x+4, y+1); int s25 = getRed(x-3, y+2); int s26 = getRed(x-2, y+2); int s27 = getRed(x-1, y+2); int s28 = getRed(x+2, y+2); int s29 = getRed(x+3, y+2); int s30 = getRed(x+4, y+2); int s31 = getRed(x-2, y+3); int s32 = getRed(x-1, y+3); int s33 = getRed(x, y+3); int s34 = getRed(x+1, y+3); int s35 = getRed(x+2, y+3); int s36 = getRed(x+3, y+3); int s37 = getRed(x-1, y+4); int s38 = getRed(x, y+4); int s39 = getRed(x+1, y+4); int s40 = getRed(x+2, y+4); int MeanInsideSurround = (s1 + s2 + s3 + s4 + s5 + s6 +                       s7 + s8 + s9 + s10 + s11 + s12 +                        s13 + s14 + s15 + s16 + s17 + s18 +                        s19 + s20 + s21 + s22 + s23 + s24 +                        s25 + s26 + s27 + s28 + s29 + s30 +                        s31 + s32 + s33 + s34 + s35 + s36 +                        s37 + s38 + s39 + s40) / 40; MeanInsideCentre = Math.abs(MeanInsideCentre); MeanInsideSurround = Math.abs(MeanInsideSurround); return Math.abs(MeanInsideCentre - MeanInsideSurround); }   private int greenReceptiveFieldInside(int x, int y)    { int c1 = getGreen(x, y-1); int c2 = getGreen(x+1, y-1); int c3 = getGreen(x-1, y); int c4 = getGreen(x, y); int c5 = getGreen(x+1, y); int c6 = getGreen(x+2, y); int c7 = getGreen(x-1, y+1); int c8 = getGreen(x, y+1); int c9 = getGreen(x+1, y+1); int c10 = getGreen(x+2, y+1); int c11 = getGreen(x, y+2); int c12 = getGreen(x+1, y+2); int MeanInsideCentre = (c1 + c2 + c3 + c4 + c5 + c6 +                     c7 + c8 + c9 + c10 + c11 + c12) / 12; int s1 = getGreen(x-1, y-3); int s2 = getGreen(x, y-3); int s3 = getGreen(x+1, y-3); int s4 = getGreen(x+2, y-3); int s5 = getGreen(x-2, y-2); int s6 = getGreen(x-1, y-2); int s7 = getGreen(x, y-2); int s8 = getGreen(x+1, y-2); int s9 = getGreen(x+2, y-2); int s10 = getGreen(x+3, y-2); int s11 = getGreen(x-3, y-1); int s12 = getGreen(x-2, y-1); int s13 = getGreen(x-1, y-1); int s14 = getGreen(x+1, y-1); int s15 = getGreen(x+2, y-1); int s16 = getGreen(x+3, y-1); int s17 = getGreen(x-3, y); int s18 = getGreen(x-2, y); int s19 = getGreen(x+3, y); int s20 = getGreen(x+4, y); int s21 = getGreen(x-3, y+1); int s22 = getGreen(x-2, y+1); int s23 = getGreen(x+3, y+1); int s24 = getGreen(x+4, y+1); int s25 = getGreen(x-3, y+2); int s26 = getGreen(x-2, y+2); int s27 = getGreen(x-1, y+2); int s28 = getGreen(x+2, y+2); int s29 = getGreen(x+3, y+2); int s30 = getGreen(x+4, y+2); int s31 = getGreen(x-2, y+3); int s32 = getGreen(x-1, y+3); int s33 = getGreen(x, y+3); int s34 = getGreen(x+1, y+3); int s35 = getGreen(x+2, y+3); int s36 = getGreen(x+3, y+3); int s37 = getGreen(x-1, y+4); int s38 = getGreen(x, y+4); int s39 = getGreen(x+1, y+4); int s40 = getGreen(x+2, y+4); int MeanInsideSurround = (s1 + s2 + s3 + s4 + s5 + s6 +                       s7 + s8 + s9 + s10 + s11 + s12 +                        s13 + s14 + s15 + s16 + s17 + s18 +                        s19 + s20 + s21 + s22 + s23 + s24 +                        s25 + s26 + s27 + s28 + s29 + s30 +                        s31 + s32 + s33 + s34 + s35 + s36 +                        s37 + s38 + s39 + s40) / 40; MeanInsideCentre = Math.abs(MeanInsideCentre); MeanInsideSurround = Math.abs(MeanInsideSurround); return Math.abs(MeanInsideCentre - MeanInsideSurround); }   private int blueReceptiveFieldInside(int x, int y)    { int c1 = getBlue(x, y-1); int c2 = getBlue(x+1, y-1); int c3 = getBlue(x-1, y); int c4 = getBlue(x, y); int c5 = getBlue(x+1, y); int c6 = getBlue(x+2, y); int c7 = getBlue(x-1, y+1); int c8 = getBlue(x, y+1); int c9 = getBlue(x+1, y+1); int c10 = getBlue(x+2, y+1); int c11 = getBlue(x, y+2); int c12 = getBlue(x+1, y+2); int MeanInsideCentre = (c1 + c2 + c3 + c4 + c5 + c6 +                     c7 + c8 + c9 + c10 + c11 + c12) / 12; int s1 = getBlue(x-1, y-3); int s2 = getBlue(x, y-3); int s3 = getBlue(x+1, y-3); int s4 = getBlue(x+2, y-3); int s5 = getBlue(x-2, y-2); int s6 = getBlue(x-1, y-2); int s7 = getBlue(x, y-2); int s8 = getBlue(x+1, y-2); int s9 = getBlue(x+2, y-2); int s10 = getBlue(x+3, y-2); int s11 = getBlue(x-3, y-1); int s12 = getBlue(x-2, y-1); int s13 = getBlue(x-1, y-1); int s14 = getBlue(x+1, y-1); int s15 = getBlue(x+2, y-1); int s16 = getBlue(x+3, y-1); int s17 = getBlue(x-3, y); int s18 = getBlue(x-2, y); int s19 = getBlue(x+3, y); int s20 = getBlue(x+4, y); int s21 = getBlue(x-3, y+1); int s22 = getBlue(x-2, y+1); int s23 = getBlue(x+3, y+1); int s24 = getBlue(x+4, y+1); int s25 = getBlue(x-3, y+2); int s26 = getBlue(x-2, y+2); int s27 = getBlue(x-1, y+2); int s28 = getBlue(x+2, y+2); int s29 = getBlue(x+3, y+2); int s30 = getBlue(x+4, y+2); int s31 = getBlue(x-2, y+3); int s32 = getBlue(x-1, y+3); int s33 = getBlue(x, y+3); int s34 = getBlue(x+1, y+3); int s35 = getBlue(x+2, y+3); int s36 = getBlue(x+3, y+3); int s37 = getBlue(x-1, y+4); int s38 = getBlue(x, y+4); int s39 = getBlue(x+1, y+4); int s40 = getBlue(x+2, y+4); int MeanInsideSurround = (s1 + s2 + s3 + s4 + s5 + s6 +                       s7 + s8 + s9 + s10 + s11 + s12 +                        s13 + s14 + s15 + s16 + s17 + s18 +                        s19 + s20 + s21 + s22 + s23 + s24 +                        s25 + s26 + s27 + s28 + s29 + s30 +                        s31 + s32 + s33 + s34 + s35 + s36 +                        s37 + s38 + s39 + s40) / 40; MeanInsideCentre = Math.abs(MeanInsideCentre); MeanInsideSurround = Math.abs(MeanInsideSurround); return Math.abs(MeanInsideCentre - MeanInsideSurround); }   private int greyReceptiveFieldInside(int x, int y)    { int c1 = getGrey(x, y-1); int c2 = getGrey(x+1, y-1); int c3 = getGrey(x-1, y); int c4 = getGrey(x, y); int c5 = getGrey(x+1, y); int c6 = getGrey(x+2, y); int c7 = getGrey(x-1, y+1); int c8 = getGrey(x, y+1); int c9 = getGrey(x+1, y+1); int c10 = getGrey(x+2, y+1); int c11 = getGrey(x, y+2); int c12 = getGrey(x+1, y+2); int MeanInsideCentre = (c1 + c2 + c3 + c4 + c5 + c6 +                     c7 + c8 + c9 + c10 + c11 + c12) / 12; int s1 = getGrey(x-1, y-3); int s2 = getGrey(x, y-3); int s3 = getGrey(x+1, y-3); int s4 = getGrey(x+2, y-3); int s5 = getGrey(x-2, y-2); int s6 = getGrey(x-1, y-2); int s7 = getGrey(x, y-2); int s8 = getGrey(x+1, y-2); int s9 = getGrey(x+2, y-2); int s10 = getGrey(x+3, y-2); int s11 = getGrey(x-3, y-1); int s12 = getGrey(x-2, y-1); int s13 = getGrey(x-1, y-1); int s14 = getGrey(x+1, y-1); int s15 = getGrey(x+2, y-1); int s16 = getGrey(x+3, y-1); int s17 = getGrey(x-3, y); int s18 = getGrey(x-2, y); int s19 = getGrey(x+3, y); int s20 = getGrey(x+4, y); int s21 = getGrey(x-3, y+1); int s22 = getGrey(x-2, y+1); int s23 = getGrey(x+3, y+1); int s24 = getGrey(x+4, y+1); int s25 = getGrey(x-3, y+2); int s26 = getGrey(x-2, y+2); int s27 = getGrey(x-1, y+2); int s28 = getGrey(x+2, y+2); int s29 = getGrey(x+3, y+2); int s30 = getGrey(x+4, y+2); int s31 = getGrey(x-2, y+3); int s32 = getGrey(x-1, y+3); int s33 = getGrey(x, y+3); int s34 = getGrey(x+1, y+3); int s35 = getGrey(x+2, y+3); int s36 = getGrey(x+3, y+3); int s37 = getGrey(x-1, y+4); int s38 = getGrey(x, y+4); int s39 = getGrey(x+1, y+4); int s40 = getGrey(x+2, y+4); int MeanInsideSurround = (s1 + s2 + s3 + s4 + s5 + s6 +                       s7 + s8 + s9 + s10 + s11 + s12 +                        s13 + s14 + s15 + s16 + s17 + s18 +                        s19 + s20 + s21 + s22 + s23 + s24 +                        s25 + s26 + s27 + s28 + s29 + s30 +                        s31 + s32 + s33 + s34 + s35 + s36 +                        s37 + s38 + s39 + s40) / 40; MeanInsideCentre = Math.abs(MeanInsideCentre); MeanInsideSurround = Math.abs(MeanInsideSurround); return Math.abs(MeanInsideCentre - MeanInsideSurround); }   public int redFalseColourSpectrum(int x, int y)    { int shade = 6 * getGrey(x, y); int red = 255; //Select a colour based on the shade number and the hue line /*more than	less than or equal to	red	green	blue 0	       255	                255	0-255	0        255	        510	                255-0	255	0        510	        765	                0	255	0-255        765	        1020	                0	255-0	255        1020	        1275	                0-255	0	255        1275	        1530	                255	0	255-0*/                       if(shade > 255 && shade <= 510) red = 510 - shade; if(shade > 510 && shade <= 765) red = 0; if(shade > 765 && shade <= 1020) red = 0; if(shade > 1020 && shade <= 1275) red = shade - 1020; return 255 - red; }   public int greenFalseColourSpectrum(int x, int y)    { int shade = 6 * getGrey(x, y); int green = 255; //Select a colour based on the shade number and the hue line /*more than	less than or equal to	red	green	blue 0	       255	                255	0-255	0        255	        510	                255-0	255	0        510	        765	                0	255	0-255        765	        1020	                0	255-0	255        1020	        1275	                0-255	0	255        1275	        1530	                255	0	255-0*/                       if(shade <= 255) green = shade; if(shade > 765 && shade <= 1020) green = 1020 - shade; if(shade > 1020 && shade <= 1275) green = 0; if(shade > 1275) green = 0; return 255 - green; }   public int blueFalseColourSpectrum(int x, int y)    { int shade = 6 * getGrey(x, y); int blue = 255; //Select a colour based on the shade number and the hue line /*more than	less than or equal to	red	green	blue 0	       255	                255	0-255	0        255	        510	                255-0	255	0        510	        765	                0	255	0-255        765	        1020	                0	255-0	255        1020	        1275	                0-255	0	255        1275	        1530	                255	0	255-0*/                       if(shade <= 255) blue = 0; if(shade > 255 && shade <= 510) blue = 0; if(shade > 510 && shade <= 765) blue = shade - 510; if(shade > 1275) blue = 1530 - shade; return 255 - blue; }   public int redFalseColourThermal(int x, int y)    { /*Select a colour based on the shade number and the hue line more than	less than or equal to	red	green	blue 0	       255	                0-255	0	0        255	        510	                255	0-255	0        510	        765	                255	255	0-255        Set as int zero by default, change if necessary */ int shade = 3 * getGrey(x, y); int red = 0; //Change to 255 (when shade > than 255) if(shade > 255) red = 255; //Change to original shade (when shade <= 255) if(shade <= 255) red = shade; return red; }   public int greenFalseColourThermal(int x, int y)    { /*Select a colour based on the shade number and the hue line more than	less than or equal to	red	green	blue 0	       255	                0-255	0	0        255	        510	                255	0-255	0        510	        765	                255	255	0-255        Set as int zero by default, change if necessary */ int shade = 3 * getGrey(x, y); int green = 0; //Change to 255 (when shade > 510) if(shade > 510) green = 255; /*Change to new shade (when shade x > 255 && x <= 510) * Shade is increasing so new shade = (shade - 255)*/ if(shade > 255 && shade <=510) green = shade - 255; return green; }   public int blueFalseColourThermal(int x, int y)    { /*Select a colour based on the shade number and the hue line more than	less than or equal to	red	green	blue 0	       255	                0-255	0	0        255	        510	                255	0-255	0        510	        765	                255	255	0-255        Set as int zero by default, change if necessary */ int shade = 3 * getGrey(x, y); int blue = 0; /*Change to new shade (when shade > 510) * Shade is increasing so new shade = (shade - 510)*/ if(shade > 510) blue = shade - 510; return blue; }   private int redCannyAngle(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = redGaussian(x-1, y-1, width, height); int z2 = redGaussian(x, y-1, width, height); int z3 = redGaussian(x+1, y-1, width, height); int z4 = redGaussian(x-1, y, width, height); int z6 = redGaussian(x+1, y, width, height); int z7 = redGaussian(x-1, y+1, width, height); int z8 = redGaussian(x, y+1, width, height); int z9 = redGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient values for x and y        * directions.*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); //Determine angle then round double angleStore = 0; int angleReturn = 0; if(gX != 0) {           angleStore = Math.toDegrees(Math.atan2(gY, gX)); angleStore = angleStore + 180; }       else {           if(gY == 0) angleStore = 0; else angleStore = 90; }       if(angleStore > 22.5 && angleStore <= 67.5) angleReturn = 45; if(angleStore > 202.5 && angleStore <= 247.5) angleReturn = 45; if(angleStore > 67.5 && angleStore <= 112.5) angleReturn = 90; if(angleStore > 247.5 && angleStore <= 292.5) angleReturn = 90; if(angleStore > 112.5 && angleStore <= 157.5) angleReturn = 135; if(angleStore > 292.5 && angleStore <= 337.5) angleReturn = 135; return angleReturn; }   private int greenCannyAngle(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = greenGaussian(x-1, y-1, width, height); int z2 = greenGaussian(x, y-1, width, height); int z3 = greenGaussian(x+1, y-1, width, height); int z4 = greenGaussian(x-1, y, width, height); int z6 = greenGaussian(x+1, y, width, height); int z7 = greenGaussian(x-1, y+1, width, height); int z8 = greenGaussian(x, y+1, width, height); int z9 = greenGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient values for x and y        * directions.*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); //Determine angle then round double angleStore = 0; int angleReturn = 0; if(gX != 0) {           angleStore = Math.toDegrees(Math.atan2(gY, gX)); angleStore = angleStore + 180; }       else {           if(gY == 0) angleStore = 0; else angleStore = 90; }       if(angleStore > 22.5 && angleStore <= 67.5) angleReturn = 45; if(angleStore > 202.5 && angleStore <= 247.5) angleReturn = 45; if(angleStore > 67.5 && angleStore <= 112.5) angleReturn = 90; if(angleStore > 247.5 && angleStore <= 292.5) angleReturn = 90; if(angleStore > 112.5 && angleStore <= 157.5) angleReturn = 135; if(angleStore > 292.5 && angleStore <= 337.5) angleReturn = 135; return angleReturn; }   private int blueCannyAngle(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = blueGaussian(x-1, y-1, width, height); int z2 = blueGaussian(x, y-1, width, height); int z3 = blueGaussian(x+1, y-1, width, height); int z4 = blueGaussian(x-1, y, width, height); int z6 = blueGaussian(x+1, y, width, height); int z7 = blueGaussian(x-1, y+1, width, height); int z8 = blueGaussian(x, y+1, width, height); int z9 = blueGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient values for x and y        * directions.*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); //Determine angle then round double angleStore = 0; int angleReturn = 0; if(gX != 0) {           angleStore = Math.toDegrees(Math.atan2(gY, gX)); angleStore = angleStore + 180; }       else {           if(gY == 0) angleStore = 0; else angleStore = 90; }       if(angleStore > 22.5 && angleStore <= 67.5) angleReturn = 45; if(angleStore > 202.5 && angleStore <= 247.5) angleReturn = 45; if(angleStore > 67.5 && angleStore <= 112.5) angleReturn = 90; if(angleStore > 247.5 && angleStore <= 292.5) angleReturn = 90; if(angleStore > 112.5 && angleStore <= 157.5) angleReturn = 135; if(angleStore > 292.5 && angleStore <= 337.5) angleReturn = 135; return angleReturn; }   private int greyCannyAngle(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = greyGaussian(x-1, y-1, width, height); int z2 = greyGaussian(x, y-1, width, height); int z3 = greyGaussian(x+1, y-1, width, height); int z4 = greyGaussian(x-1, y, width, height); int z6 = greyGaussian(x+1, y, width, height); int z7 = greyGaussian(x-1, y+1, width, height); int z8 = greyGaussian(x, y+1, width, height); int z9 = greyGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient values for x and y        * directions.*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); //Determine angle then round double angleStore = 0; int angleReturn = 0; if(gX != 0) {           angleStore = Math.toDegrees(Math.atan2(gY, gX)); angleStore = angleStore + 180; }       else {           if(gY == 0) angleStore = 0; else angleStore = 90; }       if(angleStore > 22.5 && angleStore <= 67.5) angleReturn = 45; if(angleStore > 202.5 && angleStore <= 247.5) angleReturn = 45; if(angleStore > 67.5 && angleStore <= 112.5) angleReturn = 90; if(angleStore > 247.5 && angleStore <= 292.5) angleReturn = 90; if(angleStore > 112.5 && angleStore <= 157.5) angleReturn = 135; if(angleStore > 292.5 && angleStore <= 337.5) angleReturn = 135; return angleReturn; }   private int redCannyGradient(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = redGaussian(x-1, y-1, width, height); int z2 = redGaussian(x, y-1, width, height); int z3 = redGaussian(x+1, y-1, width, height); int z4 = redGaussian(x-1, y, width, height); int z6 = redGaussian(x+1, y, width, height); int z7 = redGaussian(x-1, y+1, width, height); int z8 = redGaussian(x, y+1, width, height); int z9 = redGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient value. Convert value * to 255 if it is above 255*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sum = Math.abs(gX) + Math.abs(gY); if(sum <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int greenCannyGradient(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = greenGaussian(x-1, y-1, width, height); int z2 = greenGaussian(x, y-1, width, height); int z3 = greenGaussian(x+1, y-1, width, height); int z4 = greenGaussian(x-1, y, width, height); int z6 = greenGaussian(x+1, y, width, height); int z7 = greenGaussian(x-1, y+1, width, height); int z8 = greenGaussian(x, y+1, width, height); int z9 = greenGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient value. Convert value * to 255 if it is above 255*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sum = Math.abs(gX) + Math.abs(gY); if(sum <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int blueCannyGradient(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = blueGaussian(x-1, y-1, width, height); int z2 = blueGaussian(x, y-1, width, height); int z3 = blueGaussian(x+1, y-1, width, height); int z4 = blueGaussian(x-1, y, width, height); int z6 = blueGaussian(x+1, y, width, height); int z7 = blueGaussian(x-1, y+1, width, height); int z8 = blueGaussian(x, y+1, width, height); int z9 = blueGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient value. Convert value * to 255 if it is above 255*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sum = Math.abs(gX) + Math.abs(gY); if(sum <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private int greyCannyGradient(int x, int y)    { int width = getWidth; int height = getHeight; /*Get the Gaussian value of (x, y) and the * 8 pixels that surround it. Store these * values as z1 through to z9: *        *          (x-1)  (x)  (x+1) *   (y-1) z1     z2   z3         *    (y)   z4     z5   z6         *    (y+1) z7     z8   z9         */ int z1 = greyGaussian(x-1, y-1, width, height); int z2 = greyGaussian(x, y-1, width, height); int z3 = greyGaussian(x+1, y-1, width, height); int z4 = greyGaussian(x-1, y, width, height); int z6 = greyGaussian(x+1, y, width, height); int z7 = greyGaussian(x-1, y+1, width, height); int z8 = greyGaussian(x, y+1, width, height); int z9 = greyGaussian(x+1, y+1, width, height); /*Apply the Sobel operator to the values z1-z9 * to get the edge gradient value. Convert value * to 255 if it is above 255*/ int gX = (z7 + 2*z8 + z9) - (z1 + 2*z2 + z3); int gY = (z3 + 2*z6 + z9) - (z1 + 2*z4 + z7); int sum = Math.abs(gX) + Math.abs(gY); if(sum <= 255) return Math.abs(gX) + Math.abs(gY); else return 255; }   private Color redCannyInside(int x, int y)    { /*Returns a color value based on the direction * that the line was pointing in*/ int maximaOne = 0; int maximaTwo = 0; Color color = Color.BLACK; /*Get angle direction and edge detection * gradient for (x, y)*/ int maximaAngle = redCannyAngle(x, y); int maximaPixel = redCannyGradient(x, y); //Blue if(maximaAngle == 90) {           maximaOne = redCannyGradient (x-1, y); maximaTwo = redCannyGradient (x+1, y); }       //Red if(maximaAngle == 135) {           maximaOne = redCannyGradient (x+1, y-1); maximaTwo = redCannyGradient (x-1, y+1); }       //Yellow if(maximaAngle == 0) {           maximaOne = redCannyGradient (x, y-1); maximaTwo = redCannyGradient (x, y+1); }       //Green if(maximaAngle == 45) {           maximaOne = redCannyGradient (x-1, y-1); maximaTwo = redCannyGradient (x+1, y+1); }       color = Color.BLACK; if(maximaPixel > maximaOne) {           if(maximaPixel > maximaTwo) {               switch(maximaAngle) {                   case 0 : color = Color.YELLOW; break; case 45 : color = Color.GREEN; break; case 90 : color = Color.BLUE; break; case 135 : color = Color.RED; } //End of switch }       } //End of nested if tests if(redCannyGradient(x, y) < 80) color = Color.BLACK; return color; }       private Color greenCannyInside(int x, int y)    { /*Returns a color value based on the direction * that the line was pointing in*/ int maximaOne = 0; int maximaTwo = 0; Color color = Color.BLACK; /*Get angle direction and edge detection * gradient for (x, y)*/ int maximaAngle = greenCannyAngle(x, y); int maximaPixel = greenCannyGradient(x, y); //Blue if(maximaAngle == 90) {           maximaOne = greenCannyGradient (x-1, y); maximaTwo = greenCannyGradient (x+1, y); }       //Red if(maximaAngle == 135) {           maximaOne = greenCannyGradient (x+1, y-1); maximaTwo = greenCannyGradient (x-1, y+1); }       //Yellow if(maximaAngle == 0) {           maximaOne = greenCannyGradient (x, y-1); maximaTwo = greenCannyGradient (x, y+1); }       //Green if(maximaAngle == 45) {           maximaOne = greenCannyGradient (x-1, y-1); maximaTwo = greenCannyGradient (x+1, y+1); }       color = Color.BLACK; if(maximaPixel > maximaOne) {           if(maximaPixel > maximaTwo) {               switch(maximaAngle) {                   case 0 : color = Color.YELLOW; break; case 45 : color = Color.GREEN; break; case 90 : color = Color.BLUE; break; case 135 : color = Color.RED; } //End of switch }       } //End of nested if tests if(greenCannyGradient(x, y) < 80) color = Color.BLACK; return color; }      private Color blueCannyInside(int x, int y)    { /*Returns a color value based on the direction * that the line was pointing in*/ int maximaOne = 0; int maximaTwo = 0; Color color = Color.BLACK; /*Get angle direction and edge detection * gradient for (x, y)*/ int maximaAngle = blueCannyAngle(x, y); int maximaPixel = blueCannyGradient(x, y); //Blue if(maximaAngle == 90) {           maximaOne = blueCannyGradient (x-1, y); maximaTwo = blueCannyGradient (x+1, y); }       //Red if(maximaAngle == 135) {           maximaOne = blueCannyGradient (x+1, y-1); maximaTwo = blueCannyGradient (x-1, y+1); }       //Yellow if(maximaAngle == 0) {           maximaOne = blueCannyGradient (x, y-1); maximaTwo = blueCannyGradient (x, y+1); }       //Green if(maximaAngle == 45) {           maximaOne = blueCannyGradient (x-1, y-1); maximaTwo = blueCannyGradient (x+1, y+1); }       color = Color.BLACK; if(maximaPixel > maximaOne) {           if(maximaPixel > maximaTwo) {               switch(maximaAngle) {                   case 0 : color = Color.YELLOW; break; case 45 : color = Color.GREEN; break; case 90 : color = Color.BLUE; break; case 135 : color = Color.RED; } //End of switch }       } //End of nested if tests if(blueCannyGradient(x, y) < 80) color = Color.BLACK; return color; }       private Color greyCannyInside(int x, int y)    { /*Returns a color value based on the direction * that the line was pointing in*/ int maximaOne = 0; int maximaTwo = 0; Color color = Color.BLACK; /*Get angle direction and edge detection * gradient for (x, y)*/ int maximaAngle = greyCannyAngle(x, y); int maximaPixel = greyCannyGradient(x, y); //Blue if(maximaAngle == 90) {           maximaOne = greyCannyGradient (x-1, y); maximaTwo = greyCannyGradient (x+1, y); }       //Red if(maximaAngle == 135) {           maximaOne = greyCannyGradient (x+1, y-1); maximaTwo = greyCannyGradient (x-1, y+1); }       //Yellow if(maximaAngle == 0) {           maximaOne = greyCannyGradient (x, y-1); maximaTwo = greyCannyGradient (x, y+1); }       //Green if(maximaAngle == 45) {           maximaOne = greyCannyGradient (x-1, y-1); maximaTwo = greyCannyGradient (x+1, y+1); }       color = Color.BLACK; if(maximaPixel > maximaOne) {           if(maximaPixel > maximaTwo) {               switch(maximaAngle) {                   case 0 : color = Color.YELLOW; break; case 45 : color = Color.GREEN; break; case 90 : color = Color.BLUE; break; case 135 : color = Color.RED; } //End of switch }       } //End of nested if tests if(greyCannyGradient(x, y) < 80) color = Color.BLACK; return color; }       public Color redCannyColor(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return Color.BLACK; else return redCannyInside(x, y); }   public int redCannyInt(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return 0; else {           Color testColor = redCannyInside(x, y); if(testColor == Color.BLACK) return 0; else return 255; }   }    public Color greenCannyColor(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return Color.BLACK; else return greenCannyInside(x, y); }   public int greenCannyInt(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return 0; else {           Color testColor = greenCannyInside(x, y); if(testColor == Color.BLACK) return 0; else return 255; }   }    public Color blueCannyColor(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return Color.BLACK; else return blueCannyInside(x, y); }   public int blueCannyInt(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return 0; else {           Color testColor = blueCannyInside(x, y); if(testColor == Color.BLACK) return 0; else return 255; }   }    public Color greyCannyColor(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return Color.BLACK; else return greyCannyInside(x, y); }   public int greyCannyInt(int x, int y, int width, int height) {       /*Check to see if the values of x and y are out of bounds; * x >= width-3, y >= height-3, x < 2 and y < 2. Return black if they are, * else return the Canny at (x, y)*/ if(x >= width-4 || y >= height-4 || x < 3 || y < 3) return 0; else {           Color testColor = greyCannyInside(x, y); if(testColor == Color.BLACK) return 0; else return 255; }   }

public int convertRGB(int red, int green, int blue) {               int rgb = ((1 & 0xFF) <<24) | ((red & 0xFF) <<16) | ((green & 0xFF) <<8) | ((blue & 0xFF) <<0); return rgb; }   public void setRGB(int x, int y, int rgb) {       image.setRGB(x, y, rgb); }   public void setRGB(int x, int y, int red, int green, int blue) {       int rgb = convertRGB(red, green, blue); setRGB(x, y, rgb); }   public void setRed(int x, int y, int red) {       int green = getGreen(x, y); int blue = getBlue(x, y); int rgb = convertRGB(red, green, blue); setRGB(x, y, rgb); }   public void setGreen(int x, int y, int green) {       int red = getRed(x, y); int blue = getBlue(x, y); int rgb = convertRGB(red, green, blue); setRGB(x, y, rgb); }   public void setBlue(int x, int y, int blue) {       int green = getGreen(x, y); int red = getRed(x, y); int rgb = convertRGB(red, green, blue); setRGB(x, y, rgb); }   public void setGrey(int x, int y, int shade) {       int rgb = convertRGB(shade, shade, shade); setRGB(x, y, rgb); }   public int getRGB(int x, int y)    { return image.getRGB(x, y); }

public int getRed(int x, int y)   { int rgb = image.getRGB(x, y); return (rgb & 0x00ff0000) >> 16; }   public int getGreen(int x, int y)    { int rgb = image.getRGB(x, y); return (rgb & 0x0000ff00) >> 8; }   public int getBlue(int x, int y)    { int rgb = image.getRGB(x, y); return rgb & 0x000000ff; }   public int getGrey(int x, int y)    { int red = getRed(x, y); int green = getGreen(x, y); int blue = getBlue(x, y); return (red + green + blue) / 3; } }