Пример #1
0
  private static short[][] makeHSImap() {
    short[][] hue = new short[256][1];
    short[][] sat = new short[256][1];
    short[][] intens = new short[256][1];
    for (int i = 0; i < 256; i++) {
      hue[i][0] = (short) i;
      sat[i][0] = 255;
      intens[i][0] = (short) Math.round(255 * HSIImage.maxIntensity(i / 255.0, 1.0));
    }

    HSIImage hsiim = new HSIImage(hue, sat, intens);
    RGBImage rgbim = hsiim.makeRGBImage();
    short[][] red = rgbim.getRed();
    short[][] green = rgbim.getGreen();
    short[][] blue = rgbim.getBlue();

    short[][] colormap = new short[256][3];
    for (int i = 0; i < 256; i++) {
      colormap[i][0] = red[i][0];
      colormap[i][1] = green[i][0];
      colormap[i][2] = blue[i][0];
    }

    return colormap;
  }
Пример #2
0
  /**
   * Draw the histogram of the image on an IntensityImage with a given height and spacing between
   * the bars.
   *
   * @param cumulative Set to true for cumulative histogram.
   * @param height The heigth of the histogram.
   * @param space The space between the bars of the histogram.
   * @return An IntensityImage containing the image of the histogram.
   */
  public IntensityImage drawHistogram(boolean cumulative, int height, int space) {
    border = 30;
    int width = 255 * (1 + space) + 2 * border;
    RGBImage image = new RGBImage(height, width);
    BufferedImage bim = image.makeBufferedImage();
    Graphics g = bim.getGraphics();

    draw(cumulative, g, 0, 0, height, space);

    image.setBImage(bim);

    return new IntensityImage(image);
  }
Пример #3
0
  /**
   * A constructor that creates an IntensityImage from a RGBImage by letting the gray scale
   * intensity be the average of the red, green and blue intensities.
   *
   * @param rgbImage Original image.
   */
  public IntensityImage(RGBImage rgbImage) {
    this();

    int rows = rgbImage.getHeight();
    int cols = rgbImage.getWidth();

    data = new short[rows][cols];

    short[][] red = rgbImage.getRed();
    short[][] green = rgbImage.getGreen();
    short[][] blue = rgbImage.getBlue();

    int m;
    for (int row = 0; row < rows; row++) {
      for (int col = 0; col < cols; col++) {
        m = (red[row][col] + green[row][col] + blue[row][col]) / 3;
        data[row][col] = (short) m;
      }
    }
  }
Пример #4
0
  public void testGetNeighbor() {
    RGBImage img = new RGBImage(3, 3);
    img.setRGB(0, 0, 1, 1, 1);
    img.setRGB(1, 0, 2, 2, 2);
    img.setRGB(2, 0, 3, 3, 3);
    img.setRGB(0, 1, 4, 4, 4);
    img.setRGB(1, 1, 5, 5, 5);
    img.setRGB(2, 1, 6, 6, 6);
    img.setRGB(0, 2, 7, 7, 7);
    img.setRGB(1, 2, 8, 8, 8);
    img.setRGB(2, 2, 9, 9, 9);

    try {
      // Neighbor nbor=img.getNeighbor(1, 1, RGBColor.ALL_CHANNELS, 3);
      // System.out.println(nbor);
      // assertEquals(nbor.getValue(1, 1),5.0f);
    } catch (Exception e) {
      e.printStackTrace();
      fail("Caught an exception");
    }
  }
Пример #5
0
 /**
  * Extracts data from this image into the given RGBImage
  *
  * @param image RGBImage that would receive pixel data
  * @param destX x location within RGBImage into which the data will be written
  * @param destY y location within RGBImage into which the data will be written
  * @param x location within the source image
  * @param y location within the source image
  * @param width size of the image to extract from the source image
  * @param height size of the image to extract from the source image
  */
 public void toRGB(RGBImage image, int destX, int destY, int x, int y, int width, int height) {
   getRGB(image.getRGB(), destX + destY * image.getWidth(), x, y, width, height);
 }