Exemplo n.º 1
0
  private static BufferedImage disparity(
      ImageInteger src, BufferedImage dst, int minValue, int maxValue, int invalidColor) {
    int range = maxValue - minValue;

    for (int y = 0; y < src.height; y++) {
      for (int x = 0; x < src.width; x++) {
        int v = src.unsafe_get(x, y);

        if (v > range) {
          dst.setRGB(x, y, invalidColor);
        } else {
          int r, b;

          if (v == 0) {
            r = b = 0;
          } else {
            r = 255 * v / maxValue;
            b = 255 * (maxValue - v) / maxValue;
          }

          dst.setRGB(x, y, r << 16 | b);
        }
      }
    }

    return dst;
  }
Exemplo n.º 2
0
  private static BufferedImage grayMagnitudeTemp(
      ImageInteger src, BufferedImage dst, int maxValue) {
    int halfValue = maxValue / 2 + maxValue % 2;

    for (int y = 0; y < src.height; y++) {
      for (int x = 0; x < src.width; x++) {
        int v = Math.abs(src.get(x, y));

        int r, b;

        if (v >= halfValue) {
          r = 255 * (v - halfValue) / halfValue;
          b = 0;
        } else {
          r = 0;
          b = 255 * v / halfValue;
        }

        if (v == 0) {
          r = b = 0;
        } else {
          r = 255 * v / maxValue;
          b = 255 * (maxValue - v) / maxValue;
        }

        dst.setRGB(x, y, r << 16 | b);
      }
    }

    return dst;
  }
Exemplo n.º 3
0
  public static BufferedImage grayUnsigned(ImageInteger src, BufferedImage dst, int normalize) {
    dst = checkInputs(src, dst);

    if (src.getDataType().isSigned())
      throw new IllegalArgumentException("Can only convert unsigned images.");

    for (int y = 0; y < src.height; y++) {
      for (int x = 0; x < src.width; x++) {
        int v = src.get(x, y);

        int rgb = 255 * v / normalize;

        dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb);
      }
    }

    return dst;
  }
Exemplo n.º 4
0
 public static void set(ImageSingleBand img, int x, int y, double value) {
   if (ImageInteger.class.isAssignableFrom(img.getClass())) {
     ((ImageInteger) img).set(x, y, (int) value);
   } else if (img instanceof ImageFloat32) {
     ((ImageFloat32) img).set(x, y, (float) value);
   } else if (img instanceof ImageFloat64) {
     ((ImageFloat64) img).set(x, y, value);
   } else {
     throw new IllegalArgumentException(
         "Unknown or incompatible image type: " + img.getClass().getSimpleName());
   }
 }
Exemplo n.º 5
0
  private static BufferedImage grayMagnitude(ImageInteger src, BufferedImage dst, int maxValue) {
    for (int y = 0; y < src.height; y++) {
      for (int x = 0; x < src.width; x++) {
        int v = Math.abs(src.get(x, y));

        int rgb = 255 * v / maxValue;

        dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb);
      }
    }

    return dst;
  }
Exemplo n.º 6
0
  private static BufferedImage colorizeSign(ImageInteger src, BufferedImage dst, int normalize) {

    for (int y = 0; y < src.height; y++) {
      for (int x = 0; x < src.width; x++) {
        int v = src.get(x, y);

        int rgb;
        if (v > 0) {
          rgb = ((255 * v / normalize) << 16);
        } else {
          rgb = -((255 * v / normalize) << 8);
        }
        dst.setRGB(x, y, rgb);
      }
    }

    return dst;
  }
  public static void process(ImageInteger input, ImageInteger output, int radius, int storage[]) {
    int w = 2 * radius + 1;
    if (storage == null) {
      storage = new int[w * w];
    } else if (storage.length < w * w) {
      throw new IllegalArgumentException("'storage' must be at least of length " + (w * w));
    }

    for (int y = 0; y < radius; y++) {
      int minI = y - radius;
      int maxI = y + radius + 1;
      if (minI < 0) minI = 0;
      if (maxI > input.height) maxI = input.height;

      for (int x = 0; x < input.width; x++) {
        int minJ = x - radius;
        int maxJ = x + radius + 1;

        // bound it ot be inside the image
        if (minJ < 0) minJ = 0;
        if (maxJ > input.width) maxJ = input.width;

        int index = 0;

        for (int i = minI; i < maxI; i++) {
          for (int j = minJ; j < maxJ; j++) {
            storage[index++] = input.get(j, i);
          }
        }

        // use quick select to avoid sorting the whole list
        int median = QuickSelectArray.select(storage, index / 2, index);
        output.set(x, y, median);
      }
    }

    for (int y = input.height - radius; y < input.height; y++) {
      int minI = y - radius;
      int maxI = y + radius + 1;
      if (minI < 0) minI = 0;
      if (maxI > input.height) maxI = input.height;

      for (int x = 0; x < input.width; x++) {
        int minJ = x - radius;
        int maxJ = x + radius + 1;

        // bound it ot be inside the image
        if (minJ < 0) minJ = 0;
        if (maxJ > input.width) maxJ = input.width;

        int index = 0;

        for (int i = minI; i < maxI; i++) {
          for (int j = minJ; j < maxJ; j++) {
            storage[index++] = input.get(j, i);
          }
        }

        // use quick select to avoid sorting the whole list
        int median = QuickSelectArray.select(storage, index / 2, index);
        output.set(x, y, median);
      }
    }

    for (int y = radius; y < input.height - radius; y++) {
      int minI = y - radius;
      int maxI = y + radius + 1;
      for (int x = 0; x < radius; x++) {
        int minJ = x - radius;
        int maxJ = x + radius + 1;

        // bound it ot be inside the image
        if (minJ < 0) minJ = 0;
        if (maxJ > input.width) maxJ = input.width;

        int index = 0;

        for (int i = minI; i < maxI; i++) {
          for (int j = minJ; j < maxJ; j++) {
            storage[index++] = input.get(j, i);
          }
        }

        // use quick select to avoid sorting the whole list
        int median = QuickSelectArray.select(storage, index / 2, index);
        output.set(x, y, median);
      }
    }

    for (int y = radius; y < input.height - radius; y++) {
      int minI = y - radius;
      int maxI = y + radius + 1;
      for (int x = input.width - radius; x < input.width; x++) {
        int minJ = x - radius;
        int maxJ = x + radius + 1;

        // bound it ot be inside the image
        if (minJ < 0) minJ = 0;
        if (maxJ > input.width) maxJ = input.width;

        int index = 0;

        for (int i = minI; i < maxI; i++) {
          for (int j = minJ; j < maxJ; j++) {
            storage[index++] = input.get(j, i);
          }
        }

        // use quick select to avoid sorting the whole list
        int median = QuickSelectArray.select(storage, index / 2, index);
        output.set(x, y, median);
      }
    }
  }