コード例 #1
0
  /*
   * Implements a "logical negation" operation for a single ImageData object.
   * @param o
   * 		The ImageData object to be negated.
   */
  public ImageData match(ImageData o, double value) {
    int pixel;
    ImageData r = new ImageData();

    try {
      r =
          (ImageData)
              o
                  .clone(); // BJL: This algorithm assumes the input images are the same size, so
                            // can choose either one as a template for the result.
    } catch (Exception e) {
      System.out.println(e.getMessage());
      return null;
    }

    for (int row = 0; row < r.getNumRows(); row++) {
      for (int col = 0; col < r.getNumCols(); col++) {
        for (int band = 0; band < r.getNumBands(); band++) {
          pixel = o.getInt(row, col, band);
          if (pixel == (int) value) {
            r.set(row, col, band, 1); // if pixel = value, set it to 1
          } else {
            r.set(row, col, band, 0); // otherwise, set it to 0
          }
        }
      }
    }

    return r;
  }
コード例 #2
0
  /*
   * Converts an input image object to a binary one (with each pixel value taking on only 1 or 0).
   * @param o
   * 		input image object to be converted
   */
  public ImageData logical(ImageData o) {
    ImageData r = new ImageData();
    int pixel;

    try {
      r = (ImageData) o.clone();
    } catch (Exception e) {
      System.out.println(e.getMessage());
      return null;
    }

    // System.out.println("logical:");
    for (int row = 0; row < r.getNumRows(); row++) {

      for (int col = 0; col < r.getNumCols(); col++) {
        for (int band = 0; band < r.getNumBands(); band++) {
          pixel = r.getInt(row, col, band);
          // System.out.print(""+pixel + " ");
          if (pixel > 0) {
            r.set(row, col, band, 1); // if pixel > 0, set it to 1
          } else {
            r.set(row, col, band, 0); // otherwise, set it to 0
          }
        }
      }
      // System.out.println("");
    }
    //	System.out.println(">logical.");
    return r;
  }
コード例 #3
0
  /*
   * Implements an element-wise addition operation for a pair of ImageData objects.
   * @param o1
   * 		The first ImageData object
   * @param o2
   * 		The second ImageData object
   */
  public ImageData add(ImageData o1, ImageData o2) {

    double pixel1 = 0.0;
    double pixel2 = 0.0;
    double value = 0.0;
    ImageData r = new ImageData();

    try {
      r =
          (ImageData)
              o1
                  .clone(); // BJL: This algorithm assumes the input images are the same size, so
                            // can choose either one as a template for the result.
    } catch (Exception e) {
      System.out.println(e.getMessage());
      return null;
    }

    for (int row = 0; row < r.getNumRows(); row++) {
      for (int col = 0; col < r.getNumCols(); col++) {
        for (int band = 0; band < r.getNumBands(); band++) {
          pixel1 = o1.getInt(row, col, band);
          pixel2 = o2.getInt(row, col, band);
          value = pixel1 + pixel2;
          r.set(row, col, band, value);
        }
      }
    }
    return r;
  }
コード例 #4
0
  /*
   * Implements a "logical or" operation for a pair of ImageData objects.
   * @param o1
   * 		The first ImageData object
   * @param o2
   * 		The second ImageData object
   */
  public ImageData or(ImageData o1, ImageData o2) {

    int pixel_o1;
    int pixel_o2;
    ImageData r = new ImageData();
    ImageData bin_o1 =
        logical(
            o1); // BJL: We convert them to logical/binary form by default. Helpful if not
                 // unconverted. Otherwise, this action is redundant. Covered both cases here.
    ImageData bin_o2 = logical(o2);

    try {
      r =
          (ImageData)
              o1
                  .clone(); // BJL: This algorithm assumes the input images are the same size, so
                            // can choose either one as a template for the result.
    } catch (Exception e) {
      System.out.println(e.getMessage());
      return null;
    }

    for (int row = 0; row < r.getNumRows(); row++) {
      for (int col = 0; col < r.getNumCols(); col++) {
        for (int band = 0; band < r.getNumBands(); band++) {
          pixel_o1 = bin_o1.getInt(row, col, band);
          pixel_o2 = bin_o2.getInt(row, col, band);
          if ((pixel_o1 == 1) || (pixel_o2 == 1)) {
            r.set(row, col, band, 1); // if either pixel is 1, set it to 1
          } else {
            r.set(row, col, band, 0); // otherwise, set it to 0
          }
        }
      }
    }

    return r;
  }
コード例 #5
0
  /*
   * Implements a "logical negation" operation for a single ImageData object.
   * @param o
   * 		The ImageData object to be negated.
   */
  public ImageData not(ImageData o) {

    int pixel;
    ImageData r = new ImageData();
    ImageData bin_o = logical(o);

    try {
      r =
          (ImageData)
              bin_o
                  .clone(); // BJL: This algorithm assumes the input images are the same size, so
                            // can choose either one as a template for the result.
    } catch (Exception e) {
      System.out.println(e.getMessage());
      return null;
    }

    // System.out.println("not:");
    for (int row = 0; row < r.getNumRows(); row++) {
      for (int col = 0; col < r.getNumCols(); col++) {
        for (int band = 0; band < r.getNumBands(); band++) {
          pixel = bin_o.getInt(row, col, band);
          // System.out.print(""+pixel+" ");

          if (pixel == 1) {
            r.set(row, col, band, 0); // if pixel = 1, set it to 0
          } else {
            r.set(row, col, band, 1); // otherwise, set it to 1
          }
        }
      }
      // System.out.println();
    }
    // System.out.println(">not.");

    return r;
  }