Esempio n. 1
0
  /**
   * Sets up all the images and trackers.
   *
   * @throws IOException if the image cannot be loaded
   */
  public static void settupImages() throws IOException {
    FileSeekableStream stream = new FileSeekableStream(filePath);

    ImageDecodeParam param = null;

    ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, param);

    images = new RenderedImage[TIFFDirectory.getNumDirectories(stream)];

    System.out.println(images.length);

    for (int i = 0; i < images.length; i++) {
      images[i] = new NullOpImage(dec.decodeAsRenderedImage(i), null, null, OpImage.OP_IO_BOUND);
    }

    JFrame f = new JFrame("Trak");
    im = new ImageFrame(images);

    File save = new File(filePath + ".trak");
    if (save.exists()) {
      try {
        ObjectInputStream fromSave =
            new ObjectInputStream(new GZIPInputStream(new FileInputStream(save)));
        trackers = (DotTracker[]) fromSave.readObject();

        if (trackers.length != images.length) {
          throw new IOException("Invalid Trackers");
        }
        foundValidTrackers = true;
        System.out.println("Valid trackers found, not re-refining data");
      } catch (Exception e) {

      }
    }

    if (!foundValidTrackers) {
      trackers = new DotTracker[images.length];
    }

    f.add(im);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);

    for (int i = 0; i < images.length; i++) {
      if (!foundValidTrackers) {
        trackers[i] = new DotTracker(im.datas[i]);
      }
      trackers[i].colorRefined(im.refinedImages[i].getGraphics());
      System.out.println(i);
    }

    remakeDots();

    f.setVisible(true);
  }
Esempio n. 2
0
  /**
   * @param li ImageLevelInfo object
   * @param con JDBC Connection
   * @return the resolution for li, based on a random chosen tile
   * @throws SQLException
   * @throws IOException
   */
  protected double[] getPixelResolution(ImageLevelInfo li, Connection con)
      throws SQLException, IOException {
    double[] result = null;
    String statementString = getRandomTileStatement(li);
    PreparedStatement s = con.prepareStatement(statementString);
    ResultSet r = s.executeQuery();

    while (r.next()) {
      byte[] tileBytes = getTileBytes(r);

      if (tileBytes == null) {
        continue;
      }

      BufferedImage buffImage = null;
      li.setCanImageIOReadFromInputStream(true);
      try {
        buffImage = ImageIO.read(new ByteArrayInputStream(tileBytes));
      } catch (IOException e) {
      }

      if (buffImage == null) {
        if (LOGGER.isLoggable(Level.WARNING)) {
          LOGGER.warning(
              "Image IO cannot read from ByteInputStream,use less efficient jai methods");
        }
        li.setCanImageIOReadFromInputStream(false);
        SeekableStream stream = new ByteArraySeekableStream(tileBytes);
        String decoderName = null;

        for (String dn : ImageCodec.getDecoderNames(stream)) {
          decoderName = dn;
          break;
        }

        ImageDecoder decoder = ImageCodec.createImageDecoder(decoderName, stream, null);
        PlanarImage img = PlanarImage.wrapRenderedImage(decoder.decodeAsRenderedImage());
        buffImage = img.getAsBufferedImage();
      }

      Envelope env = getEnvelopeFromResultSet(r);

      result =
          new double[] {
            env.getWidth() / buffImage.getWidth(), env.getHeight() / buffImage.getHeight()
          };

      break;
    }

    r.close();
    s.close();

    return result;
  }
Esempio n. 3
0
  protected RenderedImage read(byte[] bytes, String type) {
    RenderedImage renderedImage = null;

    try {
      if (type.equals(TYPE_JPEG)) {
        type = "jpeg";
      }

      ImageDecoder decoder =
          ImageCodec.createImageDecoder(type, new UnsyncByteArrayInputStream(bytes), null);

      renderedImage = decoder.decodeAsRenderedImage();
    } catch (IOException ioe) {
      if (_log.isDebugEnabled()) {
        _log.debug(type + ": " + ioe.getMessage());
      }
    }

    return renderedImage;
  }