/** * Get the pixel with the minimum value. Returns an {@link FValuePixel} * which contains the location and value of the pixel. If there are multiple * pixels with the same value then the first is returned. Note that this * method assumes all pixel values are greater than 0. * * @return The minimum pixel as an {@link FValuePixel}. */ public FValuePixel minPixel() { final FValuePixel min = new FValuePixel(-1, -1); min.value = Float.MAX_VALUE; for (int y = 0; y < this.height; y++) for (int x = 0; x < this.width; x++) if (min.value > this.pixels[y][x]) { min.value = this.pixels[y][x]; min.x = x; min.y = y; } return min; }
public FValuePixel findMaximum(Rectangle window) { final FImage cornerImage = createInterestPointMap(); final FValuePixel c = cornerImage.extractROI(window).maxPixel(); c.translate(window.x, window.y); return c; }
@Override public void beforeUpdate(MBFImage frame) { sal.analyseImage(frame); final FValuePixel pt = sal.getSaliencyMap().maxPixel(); frame.internalAssign(new MBFImage(sal.getSaliencyMap(), sal.getSaliencyMap(), sal.getSaliencyMap())); frame.drawPoint(pt, RGBColour.RED, 5); final Point2d delta = pt.minus(frameCentre); final double damp = 0.03; if (delta.getX() < 0) { servos.changePanBy(-(int) (damp * delta.getX())); } else if (delta.getX() > 0) { servos.changePanBy(-(int) (damp * delta.getX())); } if (delta.getY() < 0) { servos.changeTiltBy((int) (damp * delta.getY())); } else if (delta.getY() > 0) { servos.changeTiltBy((int) (damp * delta.getY())); } }
public FValuePixel findMaximum(Rectangle window) { final FImage cornerImage = createInterestPointMap(); final FValuePixel c = cornerImage.extractROI(window).maxPixel(); c.translate(window.x, window.y); return c; }
@Override public void beforeUpdate(MBFImage frame) { sal.analyseImage(frame); final FValuePixel pt = sal.getSaliencyMap().maxPixel(); frame.internalAssign(new MBFImage(sal.getSaliencyMap(), sal.getSaliencyMap(), sal.getSaliencyMap())); frame.drawPoint(pt, RGBColour.RED, 5); final Point2d delta = pt.minus(frameCentre); final double damp = 0.03; if (delta.getX() < 0) { servos.changePanBy(-(int) (damp * delta.getX())); } else if (delta.getX() > 0) { servos.changePanBy(-(int) (damp * delta.getX())); } if (delta.getY() < 0) { servos.changeTiltBy((int) (damp * delta.getY())); } else if (delta.getY() > 0) { servos.changeTiltBy((int) (damp * delta.getY())); } }
/** * Get the pixel with the minimum value. Returns an {@link FValuePixel} * which contains the location and value of the pixel. If there are multiple * pixels with the same value then the first is returned. Note that this * method assumes all pixel values are greater than 0. * * @return The minimum pixel as an {@link FValuePixel}. */ public FValuePixel minPixel() { final FValuePixel min = new FValuePixel(-1, -1); min.value = Float.MAX_VALUE; for (int y = 0; y < this.height; y++) for (int x = 0; x < this.width; x++) if (min.value > this.pixels[y][x]) { min.value = this.pixels[y][x]; min.x = x; min.y = y; } return min; }
/** * Get the pixel with the maximum value. Returns an {@link FValuePixel} * which contains the location and value of the pixel. If there are multiple * pixels with the same value then the first is returned. Note that this * method assumes all pixel values are greater than 0. * * @return the maximum pixel as an {@link FValuePixel}. */ public FValuePixel maxPixel() { final FValuePixel max = new FValuePixel(-1, -1); max.value = -Float.MAX_VALUE; for (int y = 0; y < this.height; y++) { for (int x = 0; x < this.width; x++) { if (max.value < this.pixels[y][x]) { max.value = this.pixels[y][x]; max.x = x; max.y = y; } } } return max; }
/** * Get the pixel with the maximum value. Returns an {@link FValuePixel} * which contains the location and value of the pixel. If there are multiple * pixels with the same value then the first is returned. Note that this * method assumes all pixel values are greater than 0. * * @return the maximum pixel as an {@link FValuePixel}. */ public FValuePixel maxPixel() { final FValuePixel max = new FValuePixel(-1, -1); max.value = -Float.MAX_VALUE; for (int y = 0; y < this.height; y++) { for (int x = 0; x < this.width; x++) { if (max.value < this.pixels[y][x]) { max.value = this.pixels[y][x]; max.x = x; max.y = y; } } } return max; }
for (int x = windowHalfSize; x < mask.width - windowHalfSize - 1; x++) { if (ssd.pixels[y][x] != Float.MAX_VALUE && ssd.pixels[y][x] <= thresh) pixelList.add(new FValuePixel(x, y, ssd.pixels[y][x]));
List<FValuePixel> getUnfilledNeighbours() { final List<FValuePixel> pixels = new ArrayList<FValuePixel>(); final FImage outside = mask.process(new Erode(StructuringElement.CROSS), true); for (int y = 0; y < mask.height; y++) { for (int x = 0; x < mask.width; x++) { final int band = (int) (outside.pixels[y][x] - mask.pixels[y][x]); if (band != 0) { final float nc = countValidNeighbours(x, y); if (nc > 0) pixels.add(new FValuePixel(x, y, nc)); } } } Collections.shuffle(pixels); Collections.sort(pixels, FValuePixel.ReverseValueComparator.INSTANCE); return pixels; }
for (int x = windowHalfSize; x < mask.width - windowHalfSize - 1; x++) { if (ssd.pixels[y][x] != Float.MAX_VALUE && ssd.pixels[y][x] <= thresh) pixelList.add(new FValuePixel(x, y, ssd.pixels[y][x]));
List<FValuePixel> getUnfilledNeighbours() { final List<FValuePixel> pixels = new ArrayList<FValuePixel>(); final FImage outside = mask.process(new Erode(StructuringElement.CROSS), true); for (int y = 0; y < mask.height; y++) { for (int x = 0; x < mask.width; x++) { final int band = (int) (outside.pixels[y][x] - mask.pixels[y][x]); if (band != 0) { final float nc = countValidNeighbours(x, y); if (nc > 0) pixels.add(new FValuePixel(x, y, nc)); } } } Collections.shuffle(pixels); Collections.sort(pixels, FValuePixel.ReverseValueComparator.INSTANCE); return pixels; }
@Override protected void initMask() { final FImage outside = mask.process(new Dilate(StructuringElement.CROSS), true); flag = new byte[mask.height][mask.width]; timeMap = new FImage(outside.width, outside.height); heap = new PriorityQueue<FValuePixel>(10, FValuePixel.ValueComparator.INSTANCE); for (int y = 0; y < mask.height; y++) { for (int x = 0; x < mask.width; x++) { final int band = (int) (outside.pixels[y][x] - mask.pixels[y][x]); flag[y][x] = (byte) ((2 * outside.pixels[y][x]) - band); if (flag[y][x] == UNKNOWN) timeMap.pixels[y][x] = Float.MAX_VALUE; if (band != 0) { heap.add(new FValuePixel(x, y, timeMap.pixels[y][x])); } } } }
/** * Get the top-N "best" responses found by the template matcher. * * @param numResponses The number of responses * @param responseMap The response map * @param offsetX the amount to shift pixels in the x direction * @param offsetY the amount to shift pixels in the y direction * @param comparator the comparator for determining the "best" responses * @return the best responses found */ public static FValuePixel[] getBestResponses(int numResponses, FImage responseMap, int offsetX, int offsetY, Comparator<FValuePixel> comparator) { BoundedPriorityQueue<FValuePixel> bestResponses = new BoundedPriorityQueue<FValuePixel>(numResponses, comparator); final float[][] responseMapData = responseMap.pixels; final int scanWidth = responseMap.width; final int scanHeight = responseMap.height; FValuePixel tmpPixel = new FValuePixel(0, 0, 0); for (int y=0; y<scanHeight; y++) { for (int x=0; x<scanWidth; x++) { tmpPixel.x = x + offsetX; //account for offset to centre tmpPixel.y = y + offsetY; //account for offset to centre tmpPixel.value = responseMapData[y][x]; FValuePixel removed = bestResponses.offerItem(tmpPixel); if (removed == null) tmpPixel = new FValuePixel(0, 0, 0); else tmpPixel = removed; } } return bestResponses.toOrderedArray(new FValuePixel[numResponses]); }
@Override protected void initMask() { final FImage outside = mask.process(new Dilate(StructuringElement.CROSS), true); flag = new byte[mask.height][mask.width]; timeMap = new FImage(outside.width, outside.height); heap = new PriorityQueue<FValuePixel>(10, FValuePixel.ValueComparator.INSTANCE); for (int y = 0; y < mask.height; y++) { for (int x = 0; x < mask.width; x++) { final int band = (int) (outside.pixels[y][x] - mask.pixels[y][x]); flag[y][x] = (byte) ((2 * outside.pixels[y][x]) - band); if (flag[y][x] == UNKNOWN) timeMap.pixels[y][x] = Float.MAX_VALUE; if (band != 0) { heap.add(new FValuePixel(x, y, timeMap.pixels[y][x])); } } } }
/** * Get the top-N "best" responses found by the template matcher. * * @param numResponses The number of responses * @param responseMap The response map * @param offsetX the amount to shift pixels in the x direction * @param offsetY the amount to shift pixels in the y direction * @param comparator the comparator for determining the "best" responses * @return the best responses found */ public static FValuePixel[] getBestResponses(int numResponses, FImage responseMap, int offsetX, int offsetY, Comparator<FValuePixel> comparator) { BoundedPriorityQueue<FValuePixel> bestResponses = new BoundedPriorityQueue<FValuePixel>(numResponses, comparator); final float[][] responseMapData = responseMap.pixels; final int scanWidth = responseMap.width; final int scanHeight = responseMap.height; FValuePixel tmpPixel = new FValuePixel(0, 0, 0); for (int y=0; y<scanHeight; y++) { for (int x=0; x<scanWidth; x++) { tmpPixel.x = x + offsetX; //account for offset to centre tmpPixel.y = y + offsetY; //account for offset to centre tmpPixel.value = responseMapData[y][x]; FValuePixel removed = bestResponses.offerItem(tmpPixel); if (removed == null) tmpPixel = new FValuePixel(0, 0, 0); else tmpPixel = removed; } } return bestResponses.toOrderedArray(new FValuePixel[numResponses]); }
@Override public void performInpainting(IMAGE image) { final int width = image.getWidth(); final int height = image.getHeight(); while (!heap.isEmpty()) { final FValuePixel pix = heap.poll(); final int x = pix.x; final int y = pix.y; flag[y][x] = KNOWN; if ((x <= 1) || (y <= 1) || (x >= width - 2) || (y >= height - 2)) continue; for (final int[] p : DELTAS) { final int xp = p[0] + x, yp = p[1] + y; if (flag[yp][xp] != KNOWN) { timeMap.pixels[yp][xp] = Math.min(Math.min(Math.min( solveEikonalStep(xp - 1, yp, xp, yp - 1), solveEikonalStep(xp + 1, yp, xp, yp - 1)), solveEikonalStep(xp - 1, yp, xp, yp + 1)), solveEikonalStep(xp + 1, yp, xp, yp + 1)); if (flag[yp][xp] == UNKNOWN) { flag[yp][xp] = BAND; heap.offer(new FValuePixel(xp, yp, timeMap.pixels[yp][xp])); inpaint(xp, yp, image); } } } } }
@Override public void performInpainting(IMAGE image) { final int width = image.getWidth(); final int height = image.getHeight(); while (!heap.isEmpty()) { final FValuePixel pix = heap.poll(); final int x = pix.x; final int y = pix.y; flag[y][x] = KNOWN; if ((x <= 1) || (y <= 1) || (x >= width - 2) || (y >= height - 2)) continue; for (final int[] p : DELTAS) { final int xp = p[0] + x, yp = p[1] + y; if (flag[yp][xp] != KNOWN) { timeMap.pixels[yp][xp] = Math.min(Math.min(Math.min( solveEikonalStep(xp - 1, yp, xp, yp - 1), solveEikonalStep(xp + 1, yp, xp, yp - 1)), solveEikonalStep(xp - 1, yp, xp, yp + 1)), solveEikonalStep(xp + 1, yp, xp, yp + 1)); if (flag[yp][xp] == UNKNOWN) { flag[yp][xp] = BAND; heap.offer(new FValuePixel(xp, yp, timeMap.pixels[yp][xp])); inpaint(xp, yp, image); } } } } }