Java Code Examples for javax.media.jai.PlanarImage#wrapRenderedImage()
The following examples show how to use
javax.media.jai.PlanarImage#wrapRenderedImage() .
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: ObjectSegmentationWorker.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
private RecognitionFrame makeROIImage(RecognitionFrame rf, Shape roi) { TiledImagePainter ci = rf.bimg; if (roi != null) { Rectangle roiBounds = roi.getBounds(); if (logger.isTraceEnabled() && (roiBounds.getWidth() == 0 || roiBounds.getHeight() == 0)) { logger.trace("Warning: ROI bounds with width=0 or height=0. Skipping tile."); //return null; // instead an error message will be thrown in getAsBufferedImage } BufferedImage bi = rf.bimg.getModifiedImage(this.segmentationModel.getFeatureDescription()).getAsBufferedImage(roiBounds, rf.bimg.getImage().getColorModel()); // here it is a 'rendered' image, e.g. only with active fluo channels // BufferedImage bi = rf.bimg.getImage().getAsBufferedImage(roiBounds, rf.bimg.getImage().getColorModel()); // here it is a 'rendered' image, e.g. only with active fluo channels ci = new TiledImagePainter(PlanarImage.wrapRenderedImage(bi), "roi"); ci.getImage().setUseCache(false); } RecognitionFrame rf2 = new RecognitionFrame(ci); rf2.setClassShapes(rf.getClassShapes()); rf2.initializeClassColors(); ci.getImage().setUseCache(false); return rf2; }
Example 2
Source File: ImageFileAssistantPage1.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override protected Image doInBackground() throws Exception { RenderedImage sourceImage = FileLoadDescriptor.create(imageFilePath, null, true, null); int width = sourceImage.getWidth(); int height = sourceImage.getHeight(); float scale = (float) (targetDimension.getWidth() / width); scale = (float) Math.min(scale, targetDimension.getHeight() / height); if (scale > 1) { scale = 1.0f; } Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); RenderedImage scaledImage = ScaleDescriptor.create(sourceImage, scale, scale, 0.0f, 0.0f, interpolation, null); PlanarImage planarImage = PlanarImage.wrapRenderedImage(scaledImage); BufferedImage bufferedImage = planarImage.getAsBufferedImage(); planarImage.dispose(); return bufferedImage; }
Example 3
Source File: TMAPoints.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
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 4
Source File: NerveDetectionWorkerMultiCore.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
private PlanarImage makeROIImage(RecognitionFrame rf) { PlanarImage img = rf.bimg.getImage(); if (getSize() <= 5000 * 5000L) { if (rf.getROI() != null) { roi = rf.getROI().getScaledInstance(100d, new Point(0, 0)); } if (roi != null) { BufferedImage bi = rf.bimg.getImage().getAsBufferedImage(roi.getBounds(), rf.bimg.getImage().getColorModel()); img = PlanarImage.wrapRenderedImage(bi); roiOffsX = Math.max(roi.getBounds().x, 0); roiOffsY = Math.max(roi.getBounds().y, 0); } } return img; }
Example 5
Source File: NerveDetectionWorker.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
private PlanarImage makeROIImage(RecognitionFrame rf) { PlanarImage img = rf.bimg.getImage(); if (getRfROISize() <= 5000 * 5000L) { if (rf.getROI() != null) { roi = rf.getROI().getScaledInstance(100d, new Point(0, 0)); } if (roi != null) { BufferedImage bi = rf.bimg.getImage().getAsBufferedImage(roi.getBounds(), rf.bimg.getImage().getColorModel()); img = PlanarImage.wrapRenderedImage(bi); roiOffsX = Math.max(roi.getBounds().x, 0); roiOffsY = Math.max(roi.getBounds().y, 0); } } return img; }
Example 6
Source File: Picture.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private void setImage (RenderedImage renderedImage) throws ImageFormatException { image = PlanarImage.wrapRenderedImage(renderedImage); checkImage(); }
Example 7
Source File: RasterDirectLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Converts an image to a RGBA direct color model using a workaround via buffered image directly calling the * ColorConvert operation fails for unknown reasons ?! * * @param img image to convert * @return converted image */ public PlanarImage toDirectColorModel(RenderedImage img) { BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); BufferedImage source = new BufferedImage(img.getColorModel(), (WritableRaster) img.getData(), img .getColorModel().isAlphaPremultiplied(), null); ColorConvertOp op = new ColorConvertOp(null); op.filter(source, dest); return PlanarImage.wrapRenderedImage(dest); }
Example 8
Source File: WarpRIF.java From geowave with Apache License 2.0 | 5 votes |
/** * Creates a new instance of warp operator according to the warp object and interpolation method. * * @param paramBlock The warp and interpolation objects. */ @Override public RenderedImage create(final ParameterBlock paramBlock, final RenderingHints renderHints) { final Interpolation interp = (Interpolation) paramBlock.getObjectParameter(1); if ((interp instanceof InterpolationNearest) || (interp instanceof javax.media.jai.InterpolationNearest)) { // Get ImageLayout from renderHints if any. final ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints); RenderedImage source = paramBlock.getRenderedSource(0); final Warp warp = (Warp) paramBlock.getObjectParameter(0); final double[] backgroundValues = (double[]) paramBlock.getObjectParameter(2); ROI roi = null; final Object roi_ = paramBlock.getObjectParameter(3); if (roi_ instanceof ROI) { roi = (ROI) roi_; final PlanarImage temp = PlanarImage.wrapRenderedImage(source); temp.setProperty("ROI", roi); source = temp; } Range noData = (Range) paramBlock.getObjectParameter(4); noData = RangeFactory.convert(noData, source.getSampleModel().getDataType()); return new WarpNearestOpImage( source, renderHints, layout, warp, interp, roi, noData, backgroundValues); } return super.create(paramBlock, renderHints); }
Example 9
Source File: TMASpotEditor.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); BufferedImage img = new BufferedImage(300, 500, BufferedImage.TYPE_INT_RGB); img.getGraphics().setColor(Color.white); img.getGraphics().fillRect(0, 0, img.getWidth(), img.getHeight()); TiledImagePainter dummy = new TiledImagePainter(PlanarImage.wrapRenderedImage(img), "Dummy"); Map<Point, Point> spotMap = new HashMap<Point, Point>(); spotMap.put(new Point(20, 20), new Point(0, 0)); spotMap.put(new Point(20, 100), new Point(0, 1)); spotMap.put(new Point(20, 180), new Point(0, 2)); spotMap.put(new Point(20, 260), new Point(0, 3)); spotMap.put(new Point(20, 340), new Point(0, 4)); spotMap.put(new Point(80, 20), new Point(1, 0)); spotMap.put(new Point(80, 100), new Point(1, 1)); spotMap.put(new Point(80, 180), new Point(1, 2)); spotMap.put(new Point(80, 260), new Point(1, 3)); spotMap.put(new Point(80, 340), new Point(1, 4)); spotMap.put(new Point(140, 20), new Point(2, 0)); spotMap.put(new Point(140, 100), new Point(2, 1)); spotMap.put(new Point(140, 180), new Point(2, 2)); spotMap.put(new Point(140, 260), new Point(2, 3)); spotMap.put(new Point(140, 340), new Point(2, 4)); TMASpotEditor editor = new TMASpotEditor(spotMap, 18, dummy, true); editor.setDefaultCloseOperation(DISPOSE_ON_CLOSE); RawUtilsCommon.centerComponent(editor); editor.setVisible(true); }
Example 10
Source File: DLSegment.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public static SegmentationResult getSegmentationResult(OrbitModel segModel, BufferedImage segmented) throws Exception { IOrbitImage segimg = new OrbitImagePlanar(PlanarImage.wrapRenderedImage(segmented), "segmented"); RecognitionFrame rfSeg = new RecognitionFrame(segimg, "segmented"); List<Point> tl = new ArrayList<>(); tl.add(new Point(-1, -1)); SegmentationResult segRes = OrbitHelper.Segmentation(rfSeg, 0, segModel, tl, 1, false); return segRes; }
Example 11
Source File: NDPIImageNative.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public NDPIImageNative(String filename, int level) throws Exception { super(filename, level, false); logger.info("loading NDPI image using native ndpi library: "+filename+" ["+level+"]"); BufferedImage bi = new BufferedImage(getTileWidth(), getTileHeight(), BufferedImage.TYPE_3BYTE_BGR); PlanarImage image = PlanarImage.wrapRenderedImage(bi); if (image.getSampleModel() != null && (!image.getSampleModel().equals(sampleModel))) { this.sampleModel = image.getSampleModel(); } if (level >= getNumLevels()) throw new OrbitImageServletException("level " + level + " >= numLevels (" + getNumLevels() + ")"); logger.info(filename+" loaded ["+width+" x "+height+"]"); }
Example 12
Source File: ImageTiler.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { BufferedImage img = new BufferedImage(4000,4000,BufferedImage.TYPE_INT_RGB); PlanarImage pi = PlanarImage.wrapRenderedImage(img); for (BufferedImage tileImg: new ImageTiler(pi,512,512)) { System.out.println(tileImg); } }
Example 13
Source File: RasterLayerComponentImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Converts an image to a RGBA direct color model using a workaround via buffered image directly calling the * ColorConvert operation fails for unknown reasons ?! * * @param img * image to convert * @return converted image */ public PlanarImage toDirectColorModel(RenderedImage img) { BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); BufferedImage source = new BufferedImage(img.getColorModel(), (WritableRaster) img.getData(), img .getColorModel().isAlphaPremultiplied(), null); ColorConvertOp op = new ColorConvertOp(null); op.filter(source, dest); return PlanarImage.wrapRenderedImage(dest); }
Example 14
Source File: TMAPoints.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
private TMAPointsResult findCirclesUEP(PlanarImage image) { ImagePlus ip = new ImagePlus("TMAPoints", image.getAsBufferedImage()); // blur: this fills small 'holes' GaussianBlur blur = new GaussianBlur(); blur.blur(ip.getProcessor(), 2d); // Make Binary thresholder.applyThreshold(ip); // fill holes binary.setup("fill", null); binary.run(ip.getProcessor()); // open binary.setup("open", null); binary.run(ip.getProcessor()); // UEP edm.setup("points", null); // "points" for Ultimate points edm.run(ip.getProcessor()); PlanarImage img = PlanarImage.wrapRenderedImage(ip.getBufferedImage()); List<Point> pList = reportPoints(img, 1); double radius = guessRadius(pList); return new TMAPointsResult(pList, radius, ip.getBufferedImage()); }
Example 15
Source File: NerveDetectionWorkerMultiCore.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
private PlanarImage makeROIImage(RecognitionFrame rf, Shape roi) { PlanarImage img = rf.bimg.getImage(); BufferedImage bi = rf.bimg.getImage().getAsBufferedImage(roi.getBounds(), rf.bimg.getImage().getColorModel()); img = PlanarImage.wrapRenderedImage(bi); roiOffsX = Math.max(roi.getBounds().x, 0); roiOffsY = Math.max(roi.getBounds().y, 0); return img; }
Example 16
Source File: NDPIImageNative.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
@Override public Raster getTileData(int tileX, int tileY, boolean analysis) { try { byte[] data = null; int i = 0; while (data == null && i < NUM_TILE_TRIES) { i++; try { data = getServer().getTile(filename, level, tileX, tileY); } catch (Exception eio) { logger.debug("error loading tile, retrying... (" + i + ")"); data = null; long ms = GRIDMODE ? 5000 : 200; Thread.sleep(ms); } } if (GRIDMODE && data == null) throw new RuntimeException("error loading tile (even after " + NUM_TILE_TRIES + " tries)"); //SeekableStream in = new ByteArraySeekableStream(data); //BufferedImage bi = ImageIO.read(in); BufferedImage bi = new BufferedImage(getTileWidth(), getTileHeight(), BufferedImage.TYPE_3BYTE_BGR); // BufferedImage bi = new BufferedImage(getTileWidth(), getTileHeight(), BufferedImage.TYPE_INT_RGB); getImageUtils().createImage(data, bi); PlanarImage image = PlanarImage.wrapRenderedImage(bi); if (image.getColorModel().getNumComponents() != 1) { if (image.getSampleModel() != null && (!image.getSampleModel().equals(sampleModel))) { this.sampleModel = image.getSampleModel(); } } else { originalWasGrayScale = true; } Raster r = image.getData().createTranslatedChild(PlanarImage.tileXToX(tileX, image.getTileGridXOffset(), tileWidth), PlanarImage.tileYToY(tileY, image.getTileGridYOffset(), tileHeight)); return r; } catch (Exception e) { return null; } }
Example 17
Source File: ManipulationUtils.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
public static PlanarImage toPlanarImage(ImageProcessor ip) { return PlanarImage.wrapRenderedImage(ip.getBufferedImage()); }
Example 18
Source File: Picture.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
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 19
Source File: TMAPoints.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
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 20
Source File: TestImage3.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
public static PlanarImage decodeImage (String[] rows) { // Create the DataBuffer to hold the pixel samples final int width = rows[0].length(); final int height = rows.length; // Create Raster Raster raster; if (true) { raster = Raster.createPackedRaster (DataBuffer.TYPE_INT, width, height, new int[] {0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},// bandMasks RGBA null); } else { raster = Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE, width, height, 4,// num of bands null); } // Populate the data buffer DataBuffer dataBuffer = raster.getDataBuffer(); int index = 0; for (String row : rows) { for (int x = 0; x < width; x++) { int argb = toARGB(row.charAt(x)); dataBuffer.setElem(index, argb); index++; } } // Dump // final int size = width * height; // System.out.println("DataBuffer :"); // for (int i = 0; i < size; i++) { // if (i % width == 0) { // System.out.println(); // } // System.out.print(String.format("%8x ", dataBuffer.getElem(i))); // } // System.out.println(); // Create the image BufferedImage bufferedImage = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB); bufferedImage.setData(raster); // Dump // System.out.println("BufferedImage :"); // for (int y = 0; y < height; y++) { // System.out.println(); // for (int x = 0; x < width; x++) { // System.out.print(String.format("%8x ", bufferedImage.getRGB(x, y))); // } // } // System.out.println(); return PlanarImage.wrapRenderedImage(bufferedImage); }