public static void vertical9(
      Kernel1D_I32 kernel, ImageSInt16 image, ImageInt16 dest, int divisor, boolean includeBorder) {
    final short[] dataSrc = image.data;
    final short[] dataDst = dest.data;

    final int k1 = kernel.data[0];
    final int k2 = kernel.data[1];
    final int k3 = kernel.data[2];
    final int k4 = kernel.data[3];
    final int k5 = kernel.data[4];
    final int k6 = kernel.data[5];
    final int k7 = kernel.data[6];
    final int k8 = kernel.data[7];
    final int k9 = kernel.data[8];

    final int radius = kernel.getRadius();

    final int imgWidth = dest.getWidth();
    final int imgHeight = dest.getHeight();
    final int halfDivisor = divisor / 2;

    final int yEnd = imgHeight - radius;

    final int xBorder = includeBorder ? 0 : radius;

    for (int y = radius; y < yEnd; y++) {
      int indexDst = dest.startIndex + y * dest.stride + xBorder;
      int i = image.startIndex + (y - radius) * image.stride;
      final int iEnd = i + imgWidth - xBorder;

      for (i += xBorder; i < iEnd; i++) {
        int indexSrc = i;

        int total = (dataSrc[indexSrc]) * k1;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k2;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k3;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k4;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k5;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k6;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k7;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k8;
        indexSrc += image.stride;
        total += (dataSrc[indexSrc]) * k9;

        dataDst[indexDst++] = (short) ((total + halfDivisor) / divisor);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Fills the whole image with the specified pixel value
   *
   * @param img An image.
   * @param value The value that the image is being filled with.
   */
  public static void fill(ImageInt16 img, int value) {
    final int h = img.getHeight();
    final int w = img.getWidth();

    short[] data = img.data;

    for (int y = 0; y < h; y++) {
      int index = img.getStartIndex() + y * img.getStride();
      for (int x = 0; x < w; x++) {
        data[index++] = (short) value;
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * Computes the mean squared error (MSE) between the two images.
   *
   * @param imgA first image. Not modified.
   * @param imgB second image. Not modified.
   * @return error between the two images.
   */
  public static double computeMeanSquaredError(ImageInt16 imgA, ImageInt16 imgB) {
    final int h = imgA.getHeight();
    final int w = imgA.getWidth();

    double total = 0;

    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        double difference = imgA.get(x, y) - imgB.get(x, y);
        total += difference * difference;
      }
    }

    return total / (w * h);
  }
Ejemplo n.º 4
0
  /**
   * Sets each value in the image to a value drawn from an uniform distribution that has a range of
   * min <= X < max.
   */
  public static void randomize(ImageInt16 img, Random rand, int min, int max) {
    final int h = img.getHeight();
    final int w = img.getWidth();

    int range = max - min;

    short[] data = img.data;

    for (int y = 0; y < h; y++) {
      int index = img.getStartIndex() + y * img.getStride();
      for (int x = 0; x < w; x++) {
        data[index++] = (short) (rand.nextInt(range) + min);
      }
    }
  }