/** * Returns the neighbouring pixels for a given pixel with 4-connectedness. * If the pixel lies outside of the image the result will be null. * * @param pixel * The pixel to find the neighbours of * @return An array of pixels some of which may be null if they lie outside * of the image boundary. */ private IntValuePixel[] getNeighbourPixels_4(IntValuePixel pixel) { final IntValuePixel[] p = new IntValuePixel[4]; final int x = pixel.x; final int y = pixel.y; final int height = this.greyscaleImage.length; final int width = this.greyscaleImage[0].length; // Find the pixels int c = 0; if (x < width - 1) p[c++] = new IntValuePixel(x + 1, y, greyscaleImage[y][x + 1]); if (x > 0) p[c++] = new IntValuePixel(x - 1, y, greyscaleImage[y][x - 1]); if (y < height - 1) p[c++] = new IntValuePixel(x, y + 1, greyscaleImage[y + 1][x]); if (y > 0) p[c++] = new IntValuePixel(x, y - 1, greyscaleImage[y - 1][x]); return p; }
/** * Returns the neighbouring pixels for a given pixel with 4-connectedness. * If the pixel lies outside of the image the result will be null. * * @param pixel * The pixel to find the neighbours of * @return An array of pixels some of which may be null if they lie outside * of the image boundary. */ private IntValuePixel[] getNeighbourPixels_4(IntValuePixel pixel) { final IntValuePixel[] p = new IntValuePixel[4]; final int x = pixel.x; final int y = pixel.y; final int height = this.greyscaleImage.length; final int width = this.greyscaleImage[0].length; // Find the pixels int c = 0; if (x < width - 1) p[c++] = new IntValuePixel(x + 1, y, greyscaleImage[y][x + 1]); if (x > 0) p[c++] = new IntValuePixel(x - 1, y, greyscaleImage[y][x - 1]); if (y < height - 1) p[c++] = new IntValuePixel(x, y + 1, greyscaleImage[y + 1][x]); if (y > 0) p[c++] = new IntValuePixel(x, y - 1, greyscaleImage[y - 1][x]); return p; }
/** * Start the detection process by pouring on water at the pour point. (part * 1 and 2) * */ public void startPour() { // For each step on the downhill stream is created as // a component. this.currentPixel = startPixel; // Store the grey level of the current pixel this.currentPixel.value = greyscaleImage[this.startPixel.y][this.startPixel.x]; // Create the mask the shows where the water has access to this.accessibleMask = new BitSet(this.greyscaleImage.length * this.greyscaleImage[0].length); // Create the stack of components this.componentStack = new ArrayDeque<Component>(); // Create the heap of boundary pixels this.boundaryHeap = new BoundaryHeap(256); // Create a dummy component with a greylevel higher than // any allowed and push it onto the stack final Component dummyComponent = new Component(new IntValuePixel(-1, -1, Integer.MAX_VALUE), featureClasses); this.componentStack.push(dummyComponent); // Continue the processing at the first pixel this.processNeighbours(); // System.err.println("Component Stack: "+componentStack ); }
/** * Start the detection process by pouring on water at the pour point. (part * 1 and 2) * */ public void startPour() { // For each step on the downhill stream is created as // a component. this.currentPixel = startPixel; // Store the grey level of the current pixel this.currentPixel.value = greyscaleImage[this.startPixel.y][this.startPixel.x]; // Create the mask the shows where the water has access to this.accessibleMask = new BitSet(this.greyscaleImage.length * this.greyscaleImage[0].length); // Create the stack of components this.componentStack = new ArrayDeque<Component>(); // Create the heap of boundary pixels this.boundaryHeap = new BoundaryHeap(256); // Create a dummy component with a greylevel higher than // any allowed and push it onto the stack final Component dummyComponent = new Component(new IntValuePixel(-1, -1, Integer.MAX_VALUE), featureClasses); this.componentStack.push(dummyComponent); // Continue the processing at the first pixel this.processNeighbours(); // System.err.println("Component Stack: "+componentStack ); }
final IntValuePixel tmp = new IntValuePixel(0, 0); for (final Pixel p : cc) { tmp.x = p.x;
final IntValuePixel tmp = new IntValuePixel(0, 0); for (final Pixel p : cc) { tmp.x = p.x;