Java Code Examples for javax.media.jai.PlanarImage#getTileWidth()

The following examples show how to use javax.media.jai.PlanarImage#getTileWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IJUtils.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creats a planar image based on an ImagePlus. The originalImage is just used for dimensions and tileSize (could be replaced by its int values).
 *
 * @param ip
 * @param originalImage
 * @param fg
 * @param bg
 * @return
 */
public static PlanarImage toPlanarImage(ImagePlus ip, PlanarImage originalImage, Color fg, Color bg) {
    TiledImageWriter imageWriter = new TiledImageWriter(originalImage.getWidth(), originalImage.getHeight(), originalImage.getTileWidth(), originalImage.getTileHeight());

    // resImg
    Point[] tileArr = imageWriter.getImage().getTileIndices(null);
    int[] p = new int[4];
    int[] bgArr = new int[]{bg.getRed(), bg.getGreen(), bg.getBlue(), 255};
    int[] fgArr = new int[]{fg.getRed(), fg.getGreen(), fg.getBlue(), 255};
    for (Point tileNum : tileArr) {
        WritableRaster writeRaster = imageWriter.getImage().getWritableTile(tileNum.x, tileNum.y);
        for (int x = imageWriter.getImage().tileXToX(tileNum.x); x < Math.min(imageWriter.getImage().tileXToX(tileNum.x) + imageWriter.getImage().getTileWidth(), imageWriter.getImage().getWidth()); x++)
            for (int y = imageWriter.getImage().tileYToY(tileNum.y); y < Math.min(imageWriter.getImage().tileYToY(tileNum.y) + imageWriter.getImage().getTileHeight(), imageWriter.getImage().getHeight()); y++) {
                p = ip.getPixel(x, y);
                if (p[0] != 0) p = fgArr;
                else p = bgArr;
                writeRaster.setPixel(x, y, p);  // since it is not a gray-scale image, we just use the red channel
            } // x,y
        imageWriter.getImage().releaseWritableTile(tileNum.x, tileNum.y);
    } // tileNum

    return imageWriter.getImage();
}
 
Example 2
Source File: TiledImageWriter.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public TiledImageWriter(PlanarImage inputImage, int xOffs, int yOffs) {
    this.width = inputImage.getWidth();
    this.height = inputImage.getHeight();
    this.tileWidth = inputImage.getTileWidth();
    this.tileHeight = inputImage.getTileHeight();
    colorModel = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_sRGB),
            new int[]{8, 8, 8, 8}, true, false,
            Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);
    sampleModel = colorModel.createCompatibleSampleModel(tileWidth, tileHeight);
    image = new DiskMemImageOrbit(xOffs, yOffs, width, height, 0, 0, sampleModel, colorModel);
    ((DiskMemImageOrbit) image).setUseCommonCache(true);

    TiledImagePainter painter = new TiledImagePainter(inputImage, "");
    Graphics2D g2d = image.createGraphics();
    try { // 03.05.2010 Manuel (exception with JRE 1.5, with JRE 1.6 fine)
        painter.drawImage(g2d, xOffs, yOffs, width, height, 100d, -1);
    } catch (Throwable e) {
        //System.out.println("TiledImageWriter Error",e);
        //e.printStackTrace();
    }
}
 
Example 3
Source File: TiledImageWriter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public TiledImageWriter(PlanarImage inputImage, SampleModel sampleModel, ColorModel colorModel, int xOffs, int yOffs) {
    this.width = inputImage.getWidth();
    this.height = inputImage.getHeight();
    this.tileWidth = inputImage.getTileWidth();
    this.tileHeight = inputImage.getTileHeight();
    image = new DiskMemImageOrbit(xOffs, yOffs, width, height, 0, 0, sampleModel, colorModel);
    ((DiskMemImageOrbit) image).setUseCommonCache(true);

    TiledImagePainter painter = new TiledImagePainter(inputImage, "");
    Graphics2D g2d = image.createGraphics();
    painter.drawImage(g2d, xOffs, yOffs, width, height, 100d, -1);
}
 
Example 4
Source File: OrbitTiledImagePlanarImage.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public OrbitTiledImagePlanarImage(PlanarImage image) throws Exception {
        super("");
        this.image = image;
        this.width = image.getWidth();
        this.height = image.getHeight();
        this.tileWidth = image.getTileWidth();
        this.tileHeight = image.getTileHeight();
        this.tileGridXOffset = image.getTileGridXOffset();
        this.tileGridYOffset = image.getTileGridYOffset();
        this.minX = image.getMinX();
        this.minY = image.getMinY();
        this.numBands = image.getNumBands();

        this.colorModel = image.getColorModel();
        this.sampleModel = image.getSampleModel();

//		if (numBands==1) this.colorModel = grayColorModel; else
//		{
//			this.colorModel = rgbColorModel;
//		}

//		this.colorModel = rgbColorModel; // an OrbitTiledImage is always a RGB image
//		this.sampleModel = colorModel.createCompatibleSampleModel(tileWidth, tileHeight);

        // bugfix 20.04.2012 Manuel: colorModel is now always defined by input image (overview image problem)
        this.colorModel = image.getColorModel();
        this.sampleModel = image.getSampleModel();
        this.filename = "PlanarImage " + image.hashCode();
        // better set useCache always to false here???
    }
 
Example 5
Source File: Util.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Displays information about an image.

      @param image image to display information about */

  public static void printImageInfo(PlanarImage image) {
    String result;

    SampleModel sm = image.getSampleModel();
    ColorModel cm = image.getColorModel();
    ColorSpace cs = cm.getColorSpace();

    result  = "Width:           " + image.getWidth() + "\n";
    result += "Height:          " + image.getHeight() + "\n";
    result += "SampleModel:     " + sm.getClass().getName() + "\n";
    result += "DataType:        " + getDataType(sm.getDataType()) + "\n";
    result += "Bands:           " + sm.getNumBands() + "\n";
    result += "SampleSizes:     ";
    for (int i = 0; i < sm.getNumBands(); i++) {
      result += sm.getSampleSize(i) + " ";
    }
    result += "\n";
    result += "ColorModel:      " + cm.getClass().getName() + "\n";
    result += "ColorComponents: " + cm.getNumComponents() + "\n";
    result += "HasAlpha:        " + ((cm.hasAlpha()) ? "yes" : "no") + "\n";
    result += "ColorSpace:      " + cs.getClass().getName() + "\n";
    result += "TileSize:        " + image.getTileWidth() + "/" + image.getTileHeight() + "\n";

    System.out.print(result);
  }
 
Example 6
Source File: ManipulationUtils.java    From orbit-image-analysis with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Defines RenderingHints for JAI create operations (otherwise JAI will use defaultTileSize tiling)
 *
 * @param image
 * @return
 */
public static RenderingHints getRenderingHints(PlanarImage image) {
    ImageLayout layout = new ImageLayout(image.getMinX(), image.getMinY(), image.getWidth(), image.getHeight(), image.getTileGridXOffset(), image.getTileGridYOffset(), image.getTileWidth(), image.getTileHeight(), image.getSampleModel(), image.getColorModel());
    RenderingHints renderingHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
    return renderingHints;
}