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

The following examples show how to use javax.media.jai.PlanarImage#getWidth() . 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: TMAPoints.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public PlanarImage process(final PlanarImage image) {
    if (image == null || (image.getWidth() * image.getHeight() > 6000 * 6000L))
        throw new IllegalArgumentException("this implementation can only handle images where width*height<=6000*6000. (And image cannot be null)");

    TMAPointsResult res = findCircles(image);
    this.radius = res.getRadius();
    List<Point> pList = res.getSpotList();

    HashMap<Point, Point> pMap = clusterLines(pList);
    pMap = discardDuplicatePoints(pMap);

    BufferedImage buffImg = res.getSpotImage();
    Graphics g = buffImg.createGraphics();
    g.setColor(Color.blue);
    g.setFont(new Font("System", Font.PLAIN, 9));
    for (Point p : pMap.keySet()) {
        Point pos = pMap.get(p);
        g.drawString(pos.x + "/" + pos.y, p.x, p.y);
    }

    spotMap = pMap;

    return PlanarImage.wrapRenderedImage(buffImg);
}
 
Example 2
Source File: TMAPoints.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * returns all UEP with a threshold > min in a pointlist.
 * The UEP process has to be applied before!
 *
 * @param img
 * @param min
 * @return
 */
private List<Point> reportPoints(PlanarImage img, int min) {
    Raster r = img.getData();
    int[] rgb = new int[3];
    double d;
    List<Point> pList = new ArrayList<Point>();
    for (int x = 0; x < img.getWidth(); x++)
        for (int y = 0; y < img.getHeight(); y++) {
            rgb = r.getPixel(x, y, rgb);
            d = (rgb[0]);
            if (d > min) {
                Point p = new Point(x, y);
                pList.add(p);
                if (logger.isTraceEnabled()) {
                    logger.trace(x + "," + y + ": " + d);
                }
            }
        }
    return pList;
}
 
Example 3
Source File: IJUtils.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creats a binary ImagePlus based on a planar image. If a pixel is fg it is set to white, otherwise to black.
 *
 * @param image
 * @param fg
 * @return
 */
public static ImagePlus toBinaryImagePlus(PlanarImage image, Color fg) {
    if (image == null || (image.getWidth() * image.getHeight() > 6000 * 6000L))
        throw new IllegalArgumentException("this implementation can only handle images where width*height<=6000*6000. (And image cannot be null)");
    int width = image.getWidth();
    int height = image.getHeight();
    Raster raster = image.getData();
    int[] arr = new int[4];

    // set background to black and foreground to white for imageJ watershed
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int b = 0;
    for (int y = b; y < height - b; y++) {
        for (int x = b; x < width - b; x++) {
            arr = raster.getPixel(x, y, arr);
            if (arr[0] == fg.getRed() && arr[1] == fg.getGreen() && arr[2] == fg.getBlue()) {
                bi.setRGB(x, y, Color.WHITE.getRGB());
            } else {
                bi.setRGB(x, y, Color.BLACK.getRGB());
            }

        }
    }
    ImagePlus ip = new ImagePlus("watershed", bi);
    return ip;
}
 
Example 4
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 5
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 6
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 7
Source File: NerveDetectionWorker.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public List<Shape> detectSegmentations(int minSegmentationSize, PlanarImage sourceImage) {
    logger.trace("getSegmentations (minSegmentation=" + minSegmentationSize + ")");
    rf.initializeClassColors();
    //if (rf.getNegativeChannel() != null) rf.getNegativeChannel().initializeClassColors();
    if (sourceImage == null) return new ArrayList<Shape>(0);
    short[][] smap = new short[sourceImage.getWidth()][sourceImage.getHeight()];

    for (int x = 0; x < sourceImage.getWidth(); x++)
        for (int y = 0; y < sourceImage.getHeight(); y++)
            smap[x][y] = Short.MAX_VALUE;

    // init
    Point[] tileArr = sourceImage.getTileIndices(null);
    int c;
    for (Point tileNum : tileArr) {
        if (isCancelled()) break;
        final int b = 2;

        Raster raster = sourceImage.getTile(tileNum.x, tileNum.y);
        for (int x = sourceImage.tileXToX(tileNum.x) + b; x < Math.min(sourceImage.tileXToX(tileNum.x) + sourceImage.getTileWidth() - b, sourceImage.getWidth()); x++) {
            for (int y = sourceImage.tileYToY(tileNum.y) + b; y < Math.min(sourceImage.tileYToY(tileNum.y) + sourceImage.getTileHeight() - b, sourceImage.getHeight()); y++) {
                if (fullRoi != null && !(fullRoi.contains(x + roi.getBounds().x, y + roi.getBounds().y))) {
                    continue;
                }

                c = raster.getSample(x, y, 0) < 200 ? 0 : 1; // dark=foreground, white=background (only red channel is taken into account)
                if (c == 0) {  // not background, not assigned
                    smap[x][y] = 1; // 1
                } else {
                    smap[x][y] = 0; // 0
                }
            } //y
        } // x
    } // tileNum


    if (isCancelled()) return null;
    return findPolygons(smap, minSegmentationSize);
}
 
Example 8
Source File: AnnotationPanel.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public void run() {
    try {
        ClassShape classShape = annotation.getShape();
        if (classShape != null && classShape.getShapeList() != null) {
            if (classShape.getShapeList() != null && classShape.getShapeList().size() > 0) {
                IScaleableShape p = (IScaleableShape) classShape.getShapeList().get(0); // only the first shape

                ImageFrame iFrame = OrbitImageAnalysis.getInstance().getIFrame();
                if (iFrame != null) {
                    final long maxW = 2000;
                    Rectangle rect = p.getScaledInstance(100d, new Point(0, 0)).getBounds();
                    PlanarImage img = iFrame.recognitionFrame.bimg.getImage();
                    if ((long) rect.getWidth() * rect.getHeight() > (maxW * maxW)) {
                        if (iFrame.recognitionFrame.bimg.getMipMaps() != null && iFrame.recognitionFrame.bimg.getMipMaps().length > 0) {
                            img = iFrame.recognitionFrame.bimg.getMipMaps()[iFrame.recognitionFrame.bimg.getMipMaps().length - 1].getImage();
                            double scale = (double) img.getWidth() / (double) iFrame.recognitionFrame.bimg.getImage().getWidth();
                            rect = p.getScaledInstance(scale * 100d, new Point(0, 0)).getBounds();
                        }
                    }
                    BufferedImage bi = img.getAsBufferedImage(rect, iFrame.recognitionFrame.bimg.getImage().getColorModel());
                    bi = TiffConverter.makeScaledImage(bi, thumbnailWidth, thumbnailHeight);
                    ImageIcon icon = new ImageIcon(bi);
                    if ((cellCache != null) && (icon != null)) {
                        cellCache.put(hash, icon);
                        list.revalidate();
                        list.repaint();
                    }
                }
            }
        }

    } catch (Throwable t) {
        // can happen (e.g, outofmemory), but no problem
    }

}
 
Example 9
Source File: ImageTiler.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private PlanarImage makeTiledImage(PlanarImage img, int tileWidth, int tileHeight) {
    ImageLayout tileLayout = new ImageLayout(img);
    tileLayout.setTileWidth(tileWidth);
    tileLayout.setTileHeight(tileHeight);
    tileLayout.setSampleModel(img.getColorModel().createCompatibleSampleModel(tileWidth,tileHeight));
    tileLayout.setColorModel(img.getColorModel());
    RenderingHints tileHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, tileLayout);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(img);
    PlanarImage pi = JAI.create("format", pb, tileHints);
    pi.getWidth();
    return pi;
}
 
Example 10
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 11
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 12
Source File: GBlur.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static PlanarImage adjustBlur(PlanarImage srcImg, final int b) {
    final int width = srcImg.getWidth();
    final int height = srcImg.getHeight();
    final int[] src = srcImg.getData().getPixels(0, 0, width, height, new int[width * height * 3]);
    final int[] dest = new int[width * height * 3];

    for (int l = 0; l < b; l++) {
        if (l == 0) {
            int dum;
            for (int i = 0; i < src.length - 3; i += 3) {
                dum = src[i + 0];
                src[i + 0] = src[i + 2];
                src[i + 2] = dum;
            }
        } else {
            for (int i = 0; i < src.length - 3; i += 3) {
                src[i + 0] = dest[i + 0];
                src[i + 1] = dest[i + 1];
                src[i + 2] = dest[i + 2];
            }
        }
        for (int i = width * 3 + 3; i < src.length - 3 - width * 3; i += 3) {
            dest[i + 0] = (src[i + 0] + src[i + 0 + 3] + src[i + 0 - 3] + src[i + 0 - width * 3] + src[i + 0 + 3 - width * 3] + src[i + 0 - 3 - width * 3] + src[i + 0 + width * 3] + src[i + 0 + 3 + width * 3] + src[i + 0 - 3 + width * 3]) / 9;
            dest[i + 1] = (src[i + 1] + src[i + 1 + 3] + src[i + 1 - 3] + src[i + 1 - width * 3] + src[i + 1 + 3 - width * 3] + src[i + 1 - 3 - width * 3] + src[i + 1 + width * 3] + src[i + 1 + 3 + width * 3] + src[i + 1 - 3 + width * 3]) / 9;
            dest[i + 2] = (src[i + 2] + src[i + 2 + 3] + src[i + 2 - 3] + src[i + 2 - width * 3] + src[i + 2 + 3 - width * 3] + src[i + 2 - 3 - width * 3] + src[i + 2 + width * 3] + src[i + 2 + 3 + width * 3] + src[i + 2 - 3 + width * 3]) / 9;
        }
    }

    DataBufferByte db = new DataBufferByte(dest.length);
    for (int i = 0; i < dest.length; i++) {
        db.setElem(i, dest[i]);
    }
    WritableRaster raster = WritableRaster.createWritableRaster(srcImg.getSampleModel(), db, new Point(0, 0));
    BufferedImage bi = new BufferedImage(srcImg.getColorModel(), raster, srcImg.getColorModel().isAlphaPremultiplied(), null);
    return PlanarImage.wrapRenderedImage(bi);
}
 
Example 13
Source File: AbstractSpotModule.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public void run() {
    try {
        ClassShape classShape = annotation.getShape();
        if (classShape != null && classShape.getShapeList() != null) {
            if (classShape.getShapeList() != null && classShape.getShapeList().size() > 0) {
                IScaleableShape p = (IScaleableShape) classShape.getShapeList().get(0); // only the first shape
                ImageFrame iFrame = OrbitImageAnalysis.getInstance().getIFrame();
                if (iFrame != null) {
                    final long maxW = 2000;
                    Rectangle rect = p.getScaledInstance(100d, new Point(0, 0)).getBounds();
                    extendBB(rect, bbExtend);
                    PlanarImage img = iFrame.recognitionFrame.bimg.getImage();
                    if ((long) rect.getWidth() * rect.getHeight() > (maxW * maxW)) {
                        if (iFrame.recognitionFrame.bimg.getMipMaps() != null && iFrame.recognitionFrame.bimg.getMipMaps().length > 0) {
                            img = iFrame.recognitionFrame.bimg.getMipMaps()[iFrame.recognitionFrame.bimg.getMipMaps().length - 1].getImage();
                            double scale = (double) img.getWidth() / (double) iFrame.recognitionFrame.bimg.getImage().getWidth();
                            rect = p.getScaledInstance(scale * 100d, new Point(0, 0)).getBounds();
                        }
                    }
                    BufferedImage bi = img.getAsBufferedImage(rect, iFrame.recognitionFrame.bimg.getImage().getColorModel());
                    bi = TiffConverter.makeScaledImage(bi, thumbnailWidth, thumbnailHeight);
                    ImageIcon icon = new ImageIcon(bi);
                    if ((cellCache != null) && (icon != null)) {
                        cellCache.put(hash, icon);
                        list.revalidate();
                        list.repaint();
                    }
                }
            }
        }

    } catch (Throwable t) {
        // can happen (e.g, outofmemory), but no problem
    }

}
 
Example 14
Source File: NerveDetectionWorkerMultiCore.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public List<Shape> detectSegmentations(int minSegmentationSize, PlanarImage sourceImage, Shape roi) {
    logger.trace("getSegmentations (minSegmentation=" + minSegmentationSize + ")");
    if (sourceImage == null) return new ArrayList<Shape>(0);
    short[][] smap = new short[sourceImage.getWidth()][sourceImage.getHeight()];

    for (int x = 0; x < sourceImage.getWidth(); x++)
        for (int y = 0; y < sourceImage.getHeight(); y++)
            smap[x][y] = Short.MAX_VALUE;

    // init
    Point[] tileArr = sourceImage.getTileIndices(null);
    int c;
    for (Point tileNum : tileArr) {
        if (isCancelled()) break;
        final int b = 2;

        Raster raster = sourceImage.getTile(tileNum.x, tileNum.y);
        for (int x = sourceImage.tileXToX(tileNum.x) + b; x < Math.min(sourceImage.tileXToX(tileNum.x) + sourceImage.getTileWidth() - b, sourceImage.getWidth()); x++) {
            for (int y = sourceImage.tileYToY(tileNum.y) + b; y < Math.min(sourceImage.tileYToY(tileNum.y) + sourceImage.getTileHeight() - b, sourceImage.getHeight()); y++) {
                if (fullRoi != null && !(fullRoi.contains(x + roi.getBounds().x, y + roi.getBounds().y))) {
                    continue;
                }

                c = raster.getSample(x, y, 0) < 200 ? 0 : 1; // dark=foreground, white=background (only red channel is taken into account)
                if (c == 0) {  // not background, not assigned
                    smap[x][y] = 1; // 1
                } else {
                    smap[x][y] = 0; // 0
                }
            } //y
        } // x
    } // tileNum


    if (isCancelled()) return null;
    return findPolygons(smap, orderPoints, minSegmentationSize, roi);
}
 
Example 15
Source File: TMAPoints.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
private TMAPointsResult findCircles(PlanarImage img) {
    double r = 6d;
    double d;
    Color classCol = OrbitImageAnalysis.getInstance().getModel().getClassShapes().get(1).getColor();
    int red = classCol.getRed();
    int green = classCol.getGreen();
    int blue = classCol.getBlue();
    int[] c = new int[4];
    logger.trace("class color: " + classCol.toString());
    final Raster raster = img.getData();
    short[][] buf = new short[img.getWidth()][img.getHeight()]; // num tissue pixels buffer
    for (int x = 0; x < img.getWidth(); x++)
        for (int y = 0; y < img.getHeight(); y++) {
            // x,y is center. Now count #tissue pixel in radius around center
            for (int bx = x - (int) r; bx <= x + r; bx++) {
                if (bx < 0 || bx >= img.getWidth()) continue;
                for (int by = y - (int) r; by <= y + r; by++) {
                    if (by < 0 || by >= img.getHeight()) continue;
                    d = Point.distance(bx, by, x, y);
                    if (d <= r) {
                        c = raster.getPixel(bx, by, c);
                        if (c[0] == red && c[1] == green && c[2] == blue) {
                            buf[x][y]++;
                        }
                    }
                }
            }
        }


    BufferedImage resImg = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
    WritableRaster raster2 = resImg.getRaster();
    for (int x = 0; x < resImg.getWidth(); x++)
        for (int y = 0; y < resImg.getHeight(); y++) {
            raster2.setPixel(x, y, new int[]{buf[x][y], buf[x][y], buf[x][y]});
            //System.out.println(buf[x][y]);
        }

    // TODO: instead of UEP create TMPSpot lost, order (by score) and take highest scored spots
    // and check for intersection (maybe with min threshold)
    ImagePlus ip = new ImagePlus("TMAPoints", resImg);
    thresholder.applyThreshold(ip);
    edm.setup("points", null); // "points" for Ultimate points
    edm.run(ip.getProcessor());
    PlanarImage img1 = PlanarImage.wrapRenderedImage(ip.getBufferedImage());
    List<Point> pList = reportPoints(img1, 1);
    double radius = guessRadius(pList);
    return new TMAPointsResult(pList, radius, resImg);
}
 
Example 16
Source File: Picture.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static PlanarImage RGBToGray (PlanarImage image)
{
    logger.info("Converting RGB image to gray ...");

    if (constants.useMaxChannelInColorToGray.isSet()) {
        // We use the max value among the RGB channels
        int width = image.getWidth();
        int height = image.getHeight();
        BufferedImage im = new BufferedImage(
                width,
                height,
                BufferedImage.TYPE_BYTE_GRAY);
        WritableRaster raster = im.getRaster();
        Raster source = image.getData();
        int[] levels = new int[3];
        int maxLevel;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                source.getPixel(x, y, levels);
                maxLevel = 0;

                for (int level : levels) {
                    if (maxLevel < level) {
                        maxLevel = level;
                    }
                }

                raster.setSample(x, y, 0, maxLevel);
            }
        }

        return PlanarImage.wrapRenderedImage(im);
    } else {
        // We use luminance value based on standard RGB combination
        double[][] matrix = {
            {0.114d, 0.587d, 0.299d, 0.0d}
        };

        return JAI.create(
                "bandcombine",
                new ParameterBlock().addSource(image).add(matrix),
                null);
    }
}
 
Example 17
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;
}