Пример #1
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(ImageSInt64 img, long value) {
    final int h = img.getHeight();
    final int w = img.getWidth();

    long[] 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++] = value;
      }
    }
  }
Пример #2
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(ImageSInt64 img, Random rand, long min, long max) {
    final int h = img.getHeight();
    final int w = img.getWidth();

    long range = max - min;

    long[] 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++] = rand.nextInt((int) range) + min;
      }
    }
  }
Пример #3
0
  /** Flips the image from top to bottom */
  public static void flipVertical(ImageSInt64 img) {
    int h2 = img.height / 2;

    for (int y = 0; y < h2; y++) {
      int index1 = img.getStartIndex() + y * img.getStride();
      int index2 = img.getStartIndex() + (img.height - y - 1) * img.getStride();

      int end = index1 + img.width;

      while (index1 < end) {
        long tmp = img.data[index1];
        img.data[index1++] = img.data[index2];
        img.data[index2++] = (long) tmp;
      }
    }
  }
Пример #4
0
  /** Adds Gaussian/normal i.i.d noise to each pixel in the image. */
  public static void addGaussian(ImageSInt64 img, Random rand, double sigma, long min, long max) {
    final int h = img.getHeight();
    final int w = img.getWidth();

    long[] data = img.data;

    for (int y = 0; y < h; y++) {
      int index = img.getStartIndex() + y * img.getStride();
      for (int x = 0; x < w; x++) {
        long value = (data[index]) + (long) (rand.nextGaussian() * sigma);
        if (value < min) value = min;
        if (value > max) value = max;

        data[index++] = value;
      }
    }
  }